MP1_CalebFontenot

This commit is contained in:
2024-01-23 18:03:09 -06:00
parent 4587fe1846
commit 75ab169397
2010 changed files with 48871 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.bignerdranch.android.nerdlauncher;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.bignerdranch.android.nerdlauncher", appContext.getPackageName());
}
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.bignerdranch.android.nerdlauncher"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".NerdLauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,11 @@
package com.bignerdranch.android.nerdlauncher;
import android.support.v4.app.Fragment;
public class NerdLauncherActivity extends SingleFragmentActivity {
@Override
protected Fragment createFragment() {
return NerdLauncherFragment.newInstance();
}
}

View File

@@ -0,0 +1,119 @@
package com.bignerdranch.android.nerdlauncher;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class NerdLauncherFragment extends Fragment {
public static final String TAG = "NerdLauncherFragment";
private RecyclerView mRecyclerView;
public static NerdLauncherFragment newInstance() {
return new NerdLauncherFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_nerd_launcher, container, false);
mRecyclerView = (RecyclerView) v.findViewById(R.id.app_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
setupAdapter();
return v;
}
private void setupAdapter() {
Intent startupIntent = new Intent(Intent.ACTION_MAIN);
startupIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(startupIntent, 0);
Collections.sort(activities, new Comparator<ResolveInfo>() {
@Override
public int compare(ResolveInfo a, ResolveInfo b) {
PackageManager pm = getActivity().getPackageManager();
return String.CASE_INSENSITIVE_ORDER.compare(
a.loadLabel(pm).toString(),
b.loadLabel(pm).toString());
}
});
Log.i(TAG, "Found " + activities.size() + " activities.");
mRecyclerView.setAdapter(new ActivityAdapter(activities));
}
private class ActivityHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
private ResolveInfo mResolveInfo;
private TextView mNameTextView;
public ActivityHolder(View itemView) {
super(itemView);
mNameTextView = (TextView) itemView;
mNameTextView.setOnClickListener(this);
}
public void bindActivity(ResolveInfo resolveInfo) {
mResolveInfo = resolveInfo;
PackageManager pm = getActivity().getPackageManager();
String appName = mResolveInfo.loadLabel(pm).toString();
mNameTextView.setText(appName);
}
@Override
public void onClick(View view) {
ActivityInfo activityInfo = mResolveInfo.activityInfo;
Intent i = new Intent(Intent.ACTION_MAIN)
.setClassName(activityInfo.applicationInfo.packageName,
activityInfo.name)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
private class ActivityAdapter extends RecyclerView.Adapter<ActivityHolder> {
private final List<ResolveInfo> mActivities;
public ActivityAdapter(List<ResolveInfo> activities) {
mActivities = activities;
}
@Override
public ActivityHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View view = layoutInflater
.inflate(android.R.layout.simple_list_item_1, parent, false);
return new ActivityHolder(view);
}
@Override
public void onBindViewHolder(ActivityHolder holder, int position) {
ResolveInfo resolveInfo = mActivities.get(position);
holder.bindActivity(resolveInfo);
}
@Override
public int getItemCount() {
return mActivities.size();
}
}
}

View File

@@ -0,0 +1,27 @@
package com.bignerdranch.android.nerdlauncher;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
public abstract class SingleFragmentActivity extends AppCompatActivity {
protected abstract Fragment createFragment();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = createFragment();
fm.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
}
}
}

View File

@@ -0,0 +1,4 @@
<FrameLayout android:id="@+id/fragment_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/app_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">NerdLauncher</string>
</resources>

View File

@@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

View File

@@ -0,0 +1,17 @@
package com.bignerdranch.android.nerdlauncher;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}