我想制作一个自定义的Android Launcher应用程序,我需要一些起点来搜索它,我从github.com/AxelMarchand/Purity获得了一些自定义Launcher应用程序的代码
我有主要课程
public class Purity extends Activity {
FragmentManager app_fragment_manager;
PackageManager app_package_manager;
ActionBarDrawerToggle app_action_bar_drawer_toggle;
FrameLayout app_frame_layout;
DrawerLayout app_drawer_layout;
ListView app_list;
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.app_layout);
this.app_fragment_manager = getFragmentManager();
this.app_fragment_manager.beginTransaction().replace(R.id.app_frame_layout, new PurityFragment()).commit();
this.app_package_manager = getPackageManager();
this.app_frame_layout = (FrameLayout)findViewById(R.id.app_frame_layout);
this.app_drawer_layout = (DrawerLayout)findViewById(R.id.app_drawer_layout);
this.app_list = (ListView)findViewById(R.id.app_list);
this.app_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View parent, int position, long id) {
ApplicationInfo app = (ApplicationInfo) adapter.getItemAtPosition(position);
app_drawer_layout.closeDrawers();
startActivity(app_package_manager.getLaunchIntentForPackage(app.packageName));
}
});
this.app_list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapter, View parent, int position, long id) {
ApplicationInfo app = (ApplicationInfo) adapter.getItemAtPosition(position);
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + app.packageName));
app_drawer_layout.closeDrawers();
startActivity(intent);
return true;
}
});
this.app_action_bar_drawer_toggle = new ActionBarDrawerToggle(this, this.app_drawer_layout, android.R.color.transparent, R.string.app_empty_string, R.string.app_empty_string) {
public void onDrawerSlide(View drawerView, float slideOffset) {
float moveFactor = app_list.getWidth() * slideOffset;
app_frame_layout.setTranslationX(moveFactor);
}
};
this.app_drawer_layout.setDrawerListener(this.app_action_bar_drawer_toggle);
}
@Override
public void onStart() {
super .onStart();
List<ApplicationInfo> apps = new ArrayList<ApplicationInfo>();
List<ApplicationInfo> apps_not_sort = this.app_package_manager.getInstalledApplications(0);
for(ApplicationInfo app : apps_not_sort) {
if(this.app_package_manager.getLaunchIntentForPackage(app.packageName) != null) {
apps.add(app);
}
}
Collections.sort(apps, new Comparator<ApplicationInfo>() {
private Collator collator = Collator.getInstance();
@Override
public int compare(ApplicationInfo app0, ApplicationInfo app1) {
return collator.compare(app0.loadLabel(app_package_manager), app1.loadLabel(app_package_manager));
}
});
this.app_list.setAdapter(new PurityAdapter(this, R.layout.app_row, apps));
}
}
和PurityAdapter是
public class PurityAdapter extends ArrayAdapter<ApplicationInfo> {
public PurityAdapter(Context context, int resource, List<ApplicationInfo> apps) {
super(context, resource, apps);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
if(convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
v = inflater.inflate(R.layout.app_row, parent, false);
}else {
v = convertView;
}
ApplicationInfo app = getItem(position);
BitmapDrawable app_logo_src = (BitmapDrawable) app.loadIcon(getContext().getPackageManager());
int app_icon_bitmap_drawable_size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, getContext().getResources().getDisplayMetrics());
BitmapDrawable app_logo_rsz = new BitmapDrawable(getContext().getResources(), Bitmap.createScaledBitmap(app_logo_src.getBitmap(), app_icon_bitmap_drawable_size, app_icon_bitmap_drawable_size, false));
TextView app_label = (TextView) v.findViewById(R.id.app_row_label);
app_label.setText(app.loadLabel(getContext().getPackageManager()));
ImageView app_logo = (ImageView) v.findViewById(R.id.app_row_logo);
app_logo.setImageDrawable(app_logo_rsz);
return v;
}
}
和PurityFragment.class
public class PurityFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.app_main_fragment, container, false);
return rootView;
}
@Override
public void onResume() {
super .onResume();
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity());
this.getView().setBackground(wallpaperManager.getDrawable());
}
}
app_main_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="@+id/app_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:fontFamily="sans-serif-thin"
android:text="@string/app_name"
android:textSize="48sp"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:fontFamily="sans-serif-thin"
android:text="@string/app_unlock"/>
</LinearLayout>
</RelativeLayout>
app_layout.xml是
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/app_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="@+id/app_list"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#333"/>
</android.support.v4.widget.DrawerLayout>
清单是
<application
android:allowBackup="true"
android:icon="@android:color/transparent"
android:label="@string/app_name"
android:theme="@style/app_theme">
<activity
android:name=".Purity"
android:label="@string/app_name"
android:theme="@style/app_theme"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</activity>
</application>
所有代码都可以正常运行而不会出现错误/异常,但事情就是当我只得到屏幕时
当我滑动它没有滑动我如何以及在哪里可以进行更改以使应用程序有效?