├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── .project ├── .settings └── org.eclipse.buildship.core.prefs ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── app ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── app-release.apk ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── tan │ │ └── mytvlauncher │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── ic_launcher_round-web.png │ ├── java │ │ └── com │ │ │ └── tan │ │ │ └── mytvlauncher │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ └── AppUninstallAdapter.java │ │ │ ├── app │ │ │ ├── AppCardPresenter.java │ │ │ ├── AppDataManager.java │ │ │ ├── AppModel.java │ │ │ ├── AppUninstallActivity.java │ │ │ └── BingImage.java │ │ │ ├── card │ │ │ ├── CardModel.java │ │ │ └── CardPresenter.java │ │ │ ├── function │ │ │ ├── FunctionCardPresenter.java │ │ │ └── FunctionModel.java │ │ │ ├── loader │ │ │ └── AppItemLoader.java │ │ │ └── util │ │ │ ├── SpinnerFragment.java │ │ │ └── Tools.java │ └── res │ │ ├── drawable │ │ ├── barcode.png │ │ ├── ic_delete_black_96dp.xml │ │ ├── ic_delete_forever_black_96dp.xml │ │ ├── item_focus.png │ │ ├── pic_default.jpg │ │ └── sel_focus.xml │ │ ├── layout │ │ ├── activity_app_uninstall.xml │ │ ├── activity_main.xml │ │ └── item_app_uninstall.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── tan │ └── mytvlauncher │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── Screenshot_20170924-003632.png └── Screenshot_20170924-003642.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | app/app-release.apk 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | MyTvLauncher 4 | Project MyTvLauncher created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Sep 23 20:19:08 CST 2017 2 | connection.project.dir= 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.configuration.updateBuildConfiguration": "automatic" 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/README.md -------------------------------------------------------------------------------- /app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app 4 | Project app created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Sep 23 20:19:12 CST 2017 2 | connection.project.dir=.. 3 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/app-release.apk -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "26.0.1" 6 | defaultConfig { 7 | applicationId "com.tan.mytvlauncher" 8 | minSdkVersion 17 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | configurations.all { 28 | resolutionStrategy.force 'com.android.support:support-annotations:25.3.1' 29 | } 30 | compile 'com.android.support:appcompat-v7:25.3.1' 31 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 32 | compile 'com.android.support:leanback-v17:25.3.1' 33 | compile 'com.android.support:cardview-v7:25.3.1' 34 | compile 'com.android.support:support-annotations:25.3.1' 35 | compile 'com.github.bumptech.glide:glide:4.1.1' 36 | compile 'com.loopj.android:android-async-http:1.4.9' 37 | testCompile 'junit:junit:4.12' 38 | compile 'com.google.code.gson:gson:2.8.2' 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/tan/mytvlauncher/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.tan.mytvlauncher", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/ic_launcher_round-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/ic_launcher_round-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher; 2 | 3 | import android.app.Activity; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.content.Loader; 9 | import android.content.pm.PackageManager; 10 | import android.content.pm.ResolveInfo; 11 | import android.graphics.drawable.Drawable; 12 | import android.os.AsyncTask; 13 | import android.support.v17.leanback.app.BackgroundManager; 14 | import android.support.v17.leanback.app.BrowseFragment; 15 | import android.support.v17.leanback.widget.ArrayObjectAdapter; 16 | import android.support.v17.leanback.widget.HeaderItem; 17 | import android.support.v17.leanback.widget.ListRow; 18 | import android.support.v17.leanback.widget.ListRowPresenter; 19 | import android.os.Bundle; 20 | import android.support.v17.leanback.widget.OnItemViewClickedListener; 21 | import android.support.v17.leanback.widget.Presenter; 22 | import android.support.v17.leanback.widget.Row; 23 | import android.support.v17.leanback.widget.RowPresenter; 24 | import android.util.DisplayMetrics; 25 | import android.util.Log; 26 | 27 | import com.bumptech.glide.Glide; 28 | import com.bumptech.glide.request.target.SimpleTarget; 29 | import com.bumptech.glide.request.transition.Transition; 30 | import com.google.gson.Gson; 31 | import com.loopj.android.http.AsyncHttpClient; 32 | import com.loopj.android.http.JsonHttpResponseHandler; 33 | import com.tan.mytvlauncher.app.AppCardPresenter; 34 | import com.tan.mytvlauncher.app.AppDataManager; 35 | import com.tan.mytvlauncher.app.AppModel; 36 | import com.tan.mytvlauncher.app.BingImage; 37 | import com.tan.mytvlauncher.card.CardModel; 38 | import com.tan.mytvlauncher.card.CardPresenter; 39 | import com.tan.mytvlauncher.function.FunctionCardPresenter; 40 | import com.tan.mytvlauncher.function.FunctionModel; 41 | import com.tan.mytvlauncher.loader.AppItemLoader; 42 | import com.tan.mytvlauncher.util.SpinnerFragment; 43 | import com.tan.mytvlauncher.util.Tools; 44 | 45 | import org.json.JSONObject; 46 | 47 | import java.util.ArrayList; 48 | import java.util.Collections; 49 | import java.util.Comparator; 50 | import java.util.List; 51 | 52 | import cz.msebera.android.httpclient.Header; 53 | 54 | public class MainActivity extends Activity { 55 | protected BrowseFragment mBrowseFragment; 56 | private BackgroundManager mBackgroundManager; 57 | private ArrayObjectAdapter mUsedListRowAdapter; 58 | private DisplayMetrics mMetrics; 59 | private Context mContext; 60 | private ArrayList mAppModels; 61 | private Receiver receiver; 62 | private String backImgUrl = null; 63 | private static int CARD_L_WIDTH = 435; 64 | private static int CARD_L_HEIGHT = 300; 65 | private static final String TAG = MainActivity.class.getSimpleName(); 66 | private static final int ITEM_LOADER_ID = 1; 67 | 68 | @Override 69 | protected void onCreate(Bundle savedInstanceState) { 70 | super.onCreate(savedInstanceState); 71 | setContentView(R.layout.activity_main); 72 | mContext = this; 73 | mBrowseFragment = (BrowseFragment) getFragmentManager().findFragmentById(R.id.browse_fragment); 74 | mBrowseFragment.setHeadersState(BrowseFragment.HEADERS_DISABLED); 75 | 76 | getLoaderManager().initLoader(ITEM_LOADER_ID, null, new MainFragmentLoaderCallbacks()); 77 | 78 | mBrowseFragment.setTitle(getString(R.string.app_name)); 79 | prepareBackgroundManager(); 80 | } 81 | 82 | @Override 83 | protected void onStart() { 84 | super.onStart(); 85 | receiver = new Receiver(); 86 | IntentFilter intentFilter = new IntentFilter(); 87 | intentFilter.addAction("android.intent.action.PACKAGE_ADDED"); 88 | intentFilter.addAction("android.intent.action.PACKAGE_REMOVED"); 89 | intentFilter.addDataScheme("package"); 90 | this.registerReceiver(receiver, intentFilter); 91 | } 92 | 93 | @Override 94 | protected void onRestart() { 95 | super.onRestart(); 96 | if (backImgUrl == null) setBingImg(); 97 | else setBackgroundImage(); 98 | } 99 | 100 | @Override 101 | protected void onDestroy() { 102 | super.onDestroy(); 103 | if (receiver != null) { 104 | this.unregisterReceiver(receiver); 105 | } 106 | } 107 | 108 | @Override 109 | public void onBackPressed() { 110 | // super.onBackPressed(); 111 | } 112 | 113 | private void prepareBackgroundManager() { 114 | mBackgroundManager = BackgroundManager.getInstance(this); 115 | mBackgroundManager.attach(this.getWindow()); 116 | mMetrics = new DisplayMetrics(); 117 | getWindowManager().getDefaultDisplay().getMetrics(mMetrics); 118 | //设置背景图 119 | setBingImg(); 120 | } 121 | 122 | private void setBackgroundImage() { 123 | Glide.with(mContext) 124 | .load(backImgUrl) 125 | .into(new SimpleTarget() { 126 | @Override 127 | public void onResourceReady(Drawable resource, Transition transition) { 128 | mBackgroundManager.setDrawable(resource); 129 | } 130 | }); 131 | } 132 | 133 | private void setBingImg() { 134 | AsyncHttpClient client = new AsyncHttpClient(); 135 | client.get("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1", new JsonHttpResponseHandler() { 136 | @Override 137 | public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 138 | if (statusCode == 200) { 139 | Gson gson = new Gson(); 140 | BingImage bingImage = gson.fromJson(response.toString(), BingImage.class); 141 | List img = bingImage.getImages(); 142 | if (img != null && img.size() > 0) { 143 | backImgUrl = "https://cn.bing.com" + img.get(0).getUrl(); 144 | setBackgroundImage(); 145 | } else Log.d("main", "onSuccess: 没有获取到类型"); 146 | 147 | } 148 | } 149 | } 150 | ); 151 | } 152 | 153 | private class Receiver extends BroadcastReceiver { 154 | 155 | @Override 156 | public void onReceive(Context context, Intent intent) { 157 | //接收安装广播 158 | if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) { 159 | try { 160 | String packageName = intent.getDataString(); 161 | packageName = packageName.split(":")[1]; 162 | List list = Tools.findActivitiesForPackage(context, packageName); 163 | if (list.size() > 0) { 164 | ResolveInfo info = list.get(0); 165 | PackageManager localPackageManager = context.getPackageManager(); 166 | AppModel localAppModel = new AppModel(); 167 | localAppModel.setIcon(info.activityInfo.loadIcon(localPackageManager)); 168 | localAppModel.setName(info.activityInfo.loadLabel(localPackageManager).toString()); 169 | localAppModel.setPackageName(info.activityInfo.packageName); 170 | localAppModel.setDataDir(info.activityInfo.applicationInfo.publicSourceDir); 171 | mAppModels.add(localAppModel); 172 | getLoaderManager().restartLoader(ITEM_LOADER_ID, null, new MainFragmentLoaderCallbacks()); 173 | } else { 174 | Log.d(TAG, "onReceive: 找不到安装的app"); 175 | } 176 | } catch (Exception e) { 177 | e.printStackTrace(); 178 | } 179 | 180 | } 181 | //接收卸载广播 182 | if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) { 183 | String receiverName = intent.getDataString(); 184 | Log.d(TAG, "onReceive: " + receiverName); 185 | receiverName = receiverName.substring(8); 186 | for (int i = 0; i < mAppModels.size(); i++ 187 | ) { 188 | if (mAppModels.get(i).getPackageName().equals(receiverName)) { 189 | mAppModels.get(i).setOpenCount(mContext, 0); 190 | mAppModels.remove(i); 191 | getLoaderManager().restartLoader(ITEM_LOADER_ID, null, new MainFragmentLoaderCallbacks()); 192 | } 193 | } 194 | } 195 | } 196 | } 197 | 198 | private class MainFragmentLoaderCallbacks implements android.app.LoaderManager.LoaderCallbacks> { 199 | @Override 200 | public Loader> onCreateLoader(int id, Bundle args) { 201 | Log.d(TAG, "onCreateLoader: AppItemLoader"); 202 | mAppModels = new AppDataManager(mContext).getLauncherAppList(); 203 | return new AppItemLoader(mContext, mAppModels); 204 | } 205 | 206 | @Override 207 | public void onLoadFinished(Loader> loader, List data) { 208 | Log.d(TAG, "onLoadFinished: " + data.size()); 209 | switch (loader.getId()) { 210 | case ITEM_LOADER_ID: 211 | Log.d(TAG, "onLoadFinished: UI Update"); 212 | ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter()); 213 | rowsAdapter.addAll(0, data); 214 | mBrowseFragment.setAdapter(rowsAdapter); 215 | mBrowseFragment.setOnItemViewClickedListener(new OnItemViewClickedListener() { 216 | @Override 217 | public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) { 218 | if (item instanceof AppModel) { 219 | AppModel appModel = (AppModel) item; 220 | appModel.setOpenCount(mContext, appModel.getOpenCount() + 1); 221 | Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(appModel.getPackageName()); 222 | if (null != intent) mContext.startActivity(intent); 223 | } else if (item instanceof FunctionModel) { 224 | FunctionModel functionModel = (FunctionModel) item; 225 | Intent intent = functionModel.getIntent(); 226 | if (null != intent) 227 | startActivity(intent); 228 | } 229 | } 230 | } 231 | 232 | ); 233 | } 234 | } 235 | 236 | @Override 237 | public void onLoaderReset(Loader> loader) { 238 | mBrowseFragment.setAdapter(null); 239 | } 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/adapter/AppUninstallAdapter.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.tan.mytvlauncher.R; 12 | import com.tan.mytvlauncher.app.AppModel; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by t1569 on 2017/9/23. 18 | */ 19 | 20 | public class AppUninstallAdapter extends BaseAdapter { 21 | private final List appModels; 22 | private final Context context; 23 | 24 | public AppUninstallAdapter(Context context, List appModels) { 25 | this.context = context; 26 | this.appModels = appModels; 27 | } 28 | 29 | @Override 30 | public int getCount() { 31 | return appModels.size(); 32 | } 33 | 34 | @Override 35 | public Object getItem(int position) { 36 | return appModels.get(position); 37 | } 38 | 39 | @Override 40 | public long getItemId(int position) { 41 | return position; 42 | } 43 | 44 | @Override 45 | public View getView(int position, View convertView, ViewGroup parent) { 46 | Holder holder; 47 | if (convertView==null){ 48 | holder = new Holder(); 49 | convertView = LayoutInflater.from(context).inflate( 50 | R.layout.item_app_uninstall,null 51 | ); 52 | holder.name = (TextView) convertView.findViewById(R.id.item_app_uninstall_name); 53 | holder.icon = (ImageView)convertView.findViewById(R.id.item_app_uninstall_iv); 54 | convertView.setTag(holder); 55 | }else{ 56 | holder = (Holder)convertView.getTag(); 57 | } 58 | AppModel appModel = appModels.get(position); 59 | holder.icon.setImageDrawable(appModel.getIcon()); 60 | holder.name.setText(appModel.getName()); 61 | return convertView; 62 | } 63 | private class Holder { 64 | private TextView name; 65 | private ImageView icon; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/app/AppCardPresenter.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.app; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.support.annotation.Nullable; 5 | import android.support.v17.leanback.widget.ImageCardView; 6 | import android.support.v17.leanback.widget.Presenter; 7 | import android.util.Log; 8 | import android.util.TypedValue; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.TextView; 13 | 14 | import com.tan.mytvlauncher.R; 15 | 16 | /** 17 | * Created by t1569 on 2017/9/22. 18 | */ 19 | 20 | public class AppCardPresenter extends Presenter { 21 | private static final String TAG = "AppCardPresenter"; 22 | 23 | private static int CARD_WIDTH = 313; 24 | private static int CARD_HEIGHT = 176; 25 | private static int sDefaultBackgroundColor; 26 | private static int sSelectedBackgroundColor; 27 | private Drawable mDefaultCardImage; 28 | 29 | private int mWidth; 30 | private int mHeight; 31 | 32 | public AppCardPresenter() { 33 | this.mWidth = CARD_WIDTH; 34 | this.mHeight = CARD_HEIGHT; 35 | } 36 | 37 | public AppCardPresenter(int width, int height) { 38 | this.mWidth = width; 39 | this.mHeight = height; 40 | } 41 | 42 | private static void updateCardBackgroundColor(ImageCardView view, boolean selected) { 43 | int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor; 44 | // Both background colors should be set because the view's background is temporarily visible 45 | // during animations. 46 | view.setBackgroundColor(color); 47 | view.findViewById(R.id.info_field).setBackgroundColor(color); 48 | } 49 | 50 | @Override 51 | public ViewHolder onCreateViewHolder(ViewGroup parent) { 52 | Log.d(TAG, "onCreateViewHolder"); 53 | 54 | sDefaultBackgroundColor = parent.getResources().getColor(R.color.default_background); 55 | sSelectedBackgroundColor = parent.getResources().getColor(R.color.detail_background); 56 | 57 | ImageCardView cardView = new ImageCardView(parent.getContext()) { 58 | @Override 59 | public void setSelected(boolean selected) { 60 | updateCardBackgroundColor(this, selected); 61 | super.setSelected(selected); 62 | } 63 | }; 64 | 65 | cardView.setFocusable(true); 66 | cardView.setFocusableInTouchMode(true); 67 | TextView title = (TextView) cardView.findViewById(R.id.title_text); 68 | title.setTextSize(TypedValue.COMPLEX_UNIT_SP, mHeight / 9); 69 | updateCardBackgroundColor(cardView, false); 70 | return new ViewHolder(cardView); 71 | } 72 | 73 | @Override 74 | public void onBindViewHolder(ViewHolder viewHolder, Object item) { 75 | AppModel appModel = (AppModel) item; 76 | ImageCardView cardView = (ImageCardView) viewHolder.view; 77 | 78 | Log.d(TAG, "onBindViewHolder:" + appModel.getPackageName() + appModel.getOpenCount()); 79 | cardView.setMainImageDimensions(mWidth, mHeight); 80 | cardView.setTitleText(appModel.getName()); 81 | cardView.setMainImageScaleType(ImageView.ScaleType.FIT_CENTER); 82 | cardView.getMainImageView().setImageDrawable(appModel.getIcon()); 83 | } 84 | 85 | @Override 86 | public void onUnbindViewHolder(ViewHolder viewHolder) { 87 | Log.d(TAG, "onUnbindViewHolder"); 88 | ImageCardView cardView = (ImageCardView) viewHolder.view; 89 | // Remove references to images so that the garbage collector can free up memory 90 | cardView.setBadgeImage(null); 91 | cardView.setMainImage(null); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/app/AppDataManager.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.app; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.PackageInfo; 6 | import android.content.pm.PackageManager; 7 | import android.content.pm.ResolveInfo; 8 | 9 | import java.util.ArrayList; 10 | import java.util.Iterator; 11 | import java.util.List; 12 | 13 | /** 14 | * Created by t1569 on 2017/9/23. 15 | */ 16 | 17 | public class AppDataManager { 18 | private final Context mContext; 19 | 20 | public AppDataManager(Context context) { 21 | mContext = context; 22 | } 23 | 24 | public ArrayList getLauncherAppList() { 25 | PackageManager packageManager = mContext.getPackageManager(); 26 | Intent intent = new Intent(Intent.ACTION_MAIN); 27 | intent.addCategory(Intent.CATEGORY_LAUNCHER); 28 | List list = packageManager.queryIntentActivities(intent, 0); 29 | ArrayList appModels = new ArrayList<>(); 30 | Iterator resolveInfoIterators = null; 31 | if (list.size() != 0) { 32 | resolveInfoIterators = list.iterator(); 33 | } 34 | while (true) { 35 | if (!resolveInfoIterators.hasNext()) 36 | break; 37 | ResolveInfo resolveInfo = resolveInfoIterators.next(); 38 | AppModel appModel = new AppModel(); 39 | appModel.setIcon(resolveInfo.activityInfo.loadIcon(packageManager)); 40 | appModel.setName(resolveInfo.activityInfo.loadLabel(packageManager).toString()); 41 | appModel.setPackageName(resolveInfo.activityInfo.packageName); 42 | appModel.setDataDir(resolveInfo.activityInfo.applicationInfo.publicSourceDir); 43 | appModel.setLauncherName(resolveInfo.activityInfo.name); 44 | appModel.initOpenCount(mContext); 45 | String pkgName = resolveInfo.activityInfo.packageName; 46 | PackageInfo mPackageInfo; 47 | try { 48 | mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0); 49 | if ((mPackageInfo.applicationInfo.flags & mPackageInfo.applicationInfo.FLAG_SYSTEM) > 0) { 50 | appModel.setSysApp(true); 51 | } 52 | } catch (PackageManager.NameNotFoundException e) { 53 | e.printStackTrace(); 54 | } 55 | if (!appModel.getPackageName().equals("com.tan.mytvlauncher")) appModels.add(appModel); 56 | } 57 | return appModels; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/app/AppModel.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.app; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.NonNull; 7 | import android.util.Log; 8 | 9 | /** 10 | * Created by t1569 on 2017/9/23. 11 | */ 12 | 13 | public class AppModel { 14 | private static final String TAG = "AppModel"; 15 | private static final String PREFS_NAME = "MyAppFile"; 16 | private String dataDir; 17 | private Drawable icon; 18 | private String id; 19 | private String name; 20 | private String launcherName; 21 | private String packageName; 22 | private int pageIndex; 23 | private int position; 24 | private boolean sysApp; 25 | private int openCount; 26 | 27 | public String getDataDir() { 28 | return this.dataDir; 29 | } 30 | 31 | public Drawable getIcon() { 32 | return this.icon; 33 | } 34 | 35 | public String getId() { 36 | return this.id; 37 | } 38 | 39 | public String getName() { 40 | return this.name; 41 | } 42 | 43 | public String getPackageName() { 44 | return this.packageName; 45 | } 46 | 47 | public int getPageIndex() { 48 | return this.pageIndex; 49 | } 50 | 51 | public int getPosition() { 52 | return this.position; 53 | } 54 | 55 | public void setDataDir(String paramString) { 56 | this.dataDir = paramString; 57 | } 58 | 59 | public void setIcon(Drawable paramDrawable) { 60 | this.icon = paramDrawable; 61 | } 62 | 63 | public void setId(String paramString) { 64 | this.id = paramString; 65 | } 66 | 67 | public void setName(String paramString) { 68 | this.name = paramString; 69 | } 70 | 71 | public void setPackageName(String paramString) { 72 | this.packageName = paramString; 73 | } 74 | 75 | public void setPageIndex(int paramInt) { 76 | this.pageIndex = paramInt; 77 | } 78 | 79 | public void setPosition(int paramInt) { 80 | this.position = paramInt; 81 | } 82 | 83 | public String toString() { 84 | return "AppBean [packageName=" + this.packageName + ", name=" + this.name + ", dataDir=" + this.dataDir + "]"; 85 | } 86 | 87 | public boolean isSysApp() { 88 | return sysApp; 89 | } 90 | 91 | public void setSysApp(boolean sysApp) { 92 | this.sysApp = sysApp; 93 | } 94 | 95 | public String getLauncherName() { 96 | return launcherName; 97 | } 98 | 99 | public void setLauncherName(String launcherName) { 100 | this.launcherName = launcherName; 101 | } 102 | 103 | public int getOpenCount() { 104 | return openCount; 105 | } 106 | 107 | public void initOpenCount(Context context) { 108 | if (openCount <= 0) { 109 | SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0); 110 | openCount = settings.getInt(this.getPackageName(), 0); 111 | } 112 | } 113 | 114 | public void setOpenCount(Context context, int openCount) { 115 | SharedPreferences.Editor editor = context.getSharedPreferences(PREFS_NAME, 0).edit(); 116 | editor.putInt(this.getPackageName(), openCount); 117 | editor.commit(); 118 | Log.d(TAG, "PackName:" + this.getPackageName() +" setOpenCount: " + openCount); 119 | this.openCount = openCount; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/app/AppUninstallActivity.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.app; 2 | 3 | import android.app.Activity; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.content.pm.PackageManager; 9 | import android.content.pm.ResolveInfo; 10 | import android.net.Uri; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.os.Bundle; 13 | import android.util.Log; 14 | import android.view.View; 15 | import android.widget.AdapterView; 16 | import android.widget.ListView; 17 | 18 | import com.tan.mytvlauncher.R; 19 | import com.tan.mytvlauncher.adapter.AppUninstallAdapter; 20 | import com.tan.mytvlauncher.util.Tools; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | public class AppUninstallActivity extends Activity implements View.OnClickListener { 26 | private static final String TAG = "AppUninstallActivity"; 27 | private Context mContext; 28 | private ListView listView; 29 | private List appModels; 30 | private Receiver receiver; 31 | private AppUninstallAdapter adapter; 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | setContentView(R.layout.activity_app_uninstall); 37 | mContext = this; 38 | init(); 39 | } 40 | 41 | private void init() { 42 | appModels = new ArrayList<>(); 43 | listView = (ListView) findViewById(R.id.app_uninstall_lv); 44 | AppDataManager appDataManager = new AppDataManager(mContext); 45 | for (AppModel item : appDataManager.getLauncherAppList() 46 | ) { 47 | if (!item.isSysApp()) { 48 | appModels.add(item); 49 | } 50 | } 51 | adapter = new AppUninstallAdapter(mContext, appModels); 52 | listView.setAdapter(adapter); 53 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 54 | 55 | @Override 56 | public void onItemClick(AdapterView parent, View view, int position, long id) { 57 | Uri packageUri = Uri.parse("package:" + appModels.get(position).getPackageName()); 58 | Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri); 59 | mContext.startActivity(uninstallIntent); 60 | } 61 | }); 62 | } 63 | 64 | @Override 65 | protected void onRestart() { 66 | super.onRestart(); 67 | } 68 | 69 | @Override 70 | protected void onStart() { 71 | super.onStart(); 72 | receiver = new Receiver(); 73 | IntentFilter intentFilter = new IntentFilter(); 74 | intentFilter.addAction("android.intent.action.PACKAGE_ADDED"); 75 | intentFilter.addAction("android.intent.action.PACKAGE_REMOVED"); 76 | intentFilter.addDataScheme("package"); 77 | this.registerReceiver(receiver, intentFilter); 78 | } 79 | 80 | @Override 81 | protected void onDestroy() { 82 | super.onDestroy(); 83 | if (receiver != null) { 84 | this.unregisterReceiver(receiver); 85 | } 86 | } 87 | 88 | @Override 89 | public void onClick(View v) { 90 | 91 | } 92 | 93 | private class Receiver extends BroadcastReceiver { 94 | 95 | @Override 96 | public void onReceive(Context context, Intent intent) { 97 | //接收安装广播 98 | if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) { 99 | 100 | String packageName = intent.getDataString(); 101 | packageName = packageName.split(":")[1]; 102 | List list = Tools.findActivitiesForPackage(context, packageName); 103 | ResolveInfo info = list.get(0); 104 | PackageManager localPackageManager = context.getPackageManager(); 105 | AppModel localAppBean = new AppModel(); 106 | localAppBean.setIcon(info.activityInfo.loadIcon(localPackageManager)); 107 | localAppBean.setName(info.activityInfo.loadLabel(localPackageManager).toString()); 108 | localAppBean.setPackageName(info.activityInfo.packageName); 109 | localAppBean.setDataDir(info.activityInfo.applicationInfo.publicSourceDir); 110 | 111 | appModels.add(localAppBean); 112 | } 113 | //接收卸载广播 114 | if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) { 115 | String receiverName = intent.getDataString(); 116 | receiverName = receiverName.substring(8); 117 | AppModel appBean; 118 | for (int i = 0; i < appModels.size(); i++) { 119 | appBean = appModels.get(i); 120 | String packageName = appBean.getPackageName(); 121 | if (packageName.equals(receiverName)) { 122 | appModels.remove(i); 123 | adapter.notifyDataSetChanged(); 124 | } 125 | } 126 | } 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/app/BingImage.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.app; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by t1569 on 2017/9/23. 7 | */ 8 | 9 | public class BingImage { 10 | /** 11 | * images : [{"startdate":"20170922","fullstartdate":"201709221600","enddate":"20170923","url":"/az/hprichbg/rb/Shanghai_ZH-CN10665657954_1920x1080.jpg","urlbase":"/az/hprichbg/rb/Shanghai_ZH-CN10665657954","copyright":"【今日秋分】清晨以风筝为伴晨跑中的人,中国上海 (© Kiszon Pascal/Getty Images)","copyrightlink":"http://www.bing.com/search?q=%E7%A7%8B%E5%88%86&form=hpcapt&mkt=zh-cn","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20170922_Shanghai%22&FORM=HPQUIZ","wp":true,"hsh":"5d6129d7eb5f40bf192b890b07e0b09d","drk":1,"top":1,"bot":1,"hs":[]}] 12 | * tooltips : {"loading":"正在加载...","previous":"上一个图像","next":"下一个图像","walle":"此图片不能下载用作壁纸。","walls":"下载今日美图。仅限用作桌面壁纸。"} 13 | */ 14 | 15 | private TooltipsBean tooltips; 16 | private List images; 17 | 18 | public TooltipsBean getTooltips() { 19 | return tooltips; 20 | } 21 | 22 | public void setTooltips(TooltipsBean tooltips) { 23 | this.tooltips = tooltips; 24 | } 25 | 26 | public List getImages() { 27 | return images; 28 | } 29 | 30 | public void setImages(List images) { 31 | this.images = images; 32 | } 33 | 34 | public static class TooltipsBean { 35 | /** 36 | * loading : 正在加载... 37 | * previous : 上一个图像 38 | * next : 下一个图像 39 | * walle : 此图片不能下载用作壁纸。 40 | * walls : 下载今日美图。仅限用作桌面壁纸。 41 | */ 42 | 43 | private String loading; 44 | private String previous; 45 | private String next; 46 | private String walle; 47 | private String walls; 48 | 49 | public String getLoading() { 50 | return loading; 51 | } 52 | 53 | public void setLoading(String loading) { 54 | this.loading = loading; 55 | } 56 | 57 | public String getPrevious() { 58 | return previous; 59 | } 60 | 61 | public void setPrevious(String previous) { 62 | this.previous = previous; 63 | } 64 | 65 | public String getNext() { 66 | return next; 67 | } 68 | 69 | public void setNext(String next) { 70 | this.next = next; 71 | } 72 | 73 | public String getWalle() { 74 | return walle; 75 | } 76 | 77 | public void setWalle(String walle) { 78 | this.walle = walle; 79 | } 80 | 81 | public String getWalls() { 82 | return walls; 83 | } 84 | 85 | public void setWalls(String walls) { 86 | this.walls = walls; 87 | } 88 | } 89 | 90 | public static class ImagesBean { 91 | /** 92 | * startdate : 20170922 93 | * fullstartdate : 201709221600 94 | * enddate : 20170923 95 | * url : /az/hprichbg/rb/Shanghai_ZH-CN10665657954_1920x1080.jpg 96 | * urlbase : /az/hprichbg/rb/Shanghai_ZH-CN10665657954 97 | * copyright : 【今日秋分】清晨以风筝为伴晨跑中的人,中国上海 (© Kiszon Pascal/Getty Images) 98 | * copyrightlink : http://www.bing.com/search?q=%E7%A7%8B%E5%88%86&form=hpcapt&mkt=zh-cn 99 | * quiz : /search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20170922_Shanghai%22&FORM=HPQUIZ 100 | * wp : true 101 | * hsh : 5d6129d7eb5f40bf192b890b07e0b09d 102 | * drk : 1 103 | * top : 1 104 | * bot : 1 105 | * hs : [] 106 | */ 107 | 108 | private String startdate; 109 | private String fullstartdate; 110 | private String enddate; 111 | private String url; 112 | private String urlbase; 113 | private String copyright; 114 | private String copyrightlink; 115 | private String quiz; 116 | private boolean wp; 117 | private String hsh; 118 | private int drk; 119 | private int top; 120 | private int bot; 121 | private List hs; 122 | 123 | public String getStartdate() { 124 | return startdate; 125 | } 126 | 127 | public void setStartdate(String startdate) { 128 | this.startdate = startdate; 129 | } 130 | 131 | public String getFullstartdate() { 132 | return fullstartdate; 133 | } 134 | 135 | public void setFullstartdate(String fullstartdate) { 136 | this.fullstartdate = fullstartdate; 137 | } 138 | 139 | public String getEnddate() { 140 | return enddate; 141 | } 142 | 143 | public void setEnddate(String enddate) { 144 | this.enddate = enddate; 145 | } 146 | 147 | public String getUrl() { 148 | return url; 149 | } 150 | 151 | public void setUrl(String url) { 152 | this.url = url; 153 | } 154 | 155 | public String getUrlbase() { 156 | return urlbase; 157 | } 158 | 159 | public void setUrlbase(String urlbase) { 160 | this.urlbase = urlbase; 161 | } 162 | 163 | public String getCopyright() { 164 | return copyright; 165 | } 166 | 167 | public void setCopyright(String copyright) { 168 | this.copyright = copyright; 169 | } 170 | 171 | public String getCopyrightlink() { 172 | return copyrightlink; 173 | } 174 | 175 | public void setCopyrightlink(String copyrightlink) { 176 | this.copyrightlink = copyrightlink; 177 | } 178 | 179 | public String getQuiz() { 180 | return quiz; 181 | } 182 | 183 | public void setQuiz(String quiz) { 184 | this.quiz = quiz; 185 | } 186 | 187 | public boolean isWp() { 188 | return wp; 189 | } 190 | 191 | public void setWp(boolean wp) { 192 | this.wp = wp; 193 | } 194 | 195 | public String getHsh() { 196 | return hsh; 197 | } 198 | 199 | public void setHsh(String hsh) { 200 | this.hsh = hsh; 201 | } 202 | 203 | public int getDrk() { 204 | return drk; 205 | } 206 | 207 | public void setDrk(int drk) { 208 | this.drk = drk; 209 | } 210 | 211 | public int getTop() { 212 | return top; 213 | } 214 | 215 | public void setTop(int top) { 216 | this.top = top; 217 | } 218 | 219 | public int getBot() { 220 | return bot; 221 | } 222 | 223 | public void setBot(int bot) { 224 | this.bot = bot; 225 | } 226 | 227 | public List getHs() { 228 | return hs; 229 | } 230 | 231 | public void setHs(List hs) { 232 | this.hs = hs; 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/card/CardModel.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.card; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by t1569 on 2017/9/22. 8 | */ 9 | 10 | public class CardModel { 11 | private long id; 12 | private String title; 13 | private String desc; 14 | private String imgUrl; 15 | 16 | public CardModel(final long id, final String title, final String desc, final String imgUrl) { 17 | this.id = id; 18 | this.title = title; 19 | this.desc = desc; 20 | this.imgUrl = imgUrl; 21 | } 22 | 23 | public CardModel() { 24 | 25 | } 26 | 27 | public long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getTitle() { 36 | return title; 37 | } 38 | 39 | public void setTitle(String title) { 40 | this.title = title; 41 | } 42 | 43 | public String getDesc() { 44 | return desc; 45 | } 46 | 47 | public void setDesc(String desc) { 48 | this.desc = desc; 49 | } 50 | 51 | public String getImgUrl() { 52 | return imgUrl; 53 | } 54 | 55 | public void setImgUrl(String imgUrl) { 56 | this.imgUrl = imgUrl; 57 | } 58 | 59 | public static List getCardModels() { 60 | List cardModels = new ArrayList<>(); 61 | String titles[] = { 62 | "视频", 63 | "音乐", 64 | "直播" 65 | }; 66 | for (int i = 0; i < titles.length; i++) { 67 | CardModel cardModel = new CardModel(i, titles[i], "", ""); 68 | cardModels.add(cardModel); 69 | } 70 | return cardModels; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/card/CardPresenter.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.card; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.support.v17.leanback.widget.ImageCardView; 5 | import android.support.v17.leanback.widget.Presenter; 6 | import android.util.Log; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | 10 | import com.tan.mytvlauncher.R; 11 | 12 | /** 13 | * Created by t1569 on 2017/9/22. 14 | */ 15 | 16 | public class CardPresenter extends Presenter { 17 | private static final String TAG = "CardPresenter"; 18 | 19 | private static int CARD_WIDTH = 430; 20 | private static int CARD_HEIGHT = 220; 21 | private static int sSelectedBackgroundColor; 22 | private static int sDefaultBackgroundColor; 23 | private Drawable mDefaultCardImage; 24 | 25 | private static void updateCardBackgroundColor(ImageCardView view, boolean selected) { 26 | int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor; 27 | // Both background colors should be set because the view's background is temporarily visible 28 | // during animations. 29 | view.setBackgroundColor(color); 30 | view.findViewById(R.id.info_field).setBackgroundColor(color); 31 | } 32 | 33 | @Override 34 | public ViewHolder onCreateViewHolder(ViewGroup parent) { 35 | Log.d(TAG, "onCreateViewHolder"); 36 | 37 | sDefaultBackgroundColor = parent.getResources().getColor(R.color.default_background); 38 | sSelectedBackgroundColor = parent.getResources().getColor(R.color.detail_background); 39 | 40 | ImageCardView cardView = new ImageCardView(parent.getContext()) { 41 | @Override 42 | public void setSelected(boolean selected) { 43 | updateCardBackgroundColor(this, selected); 44 | super.setSelected(selected); 45 | } 46 | }; 47 | 48 | cardView.setFocusable(true); 49 | cardView.setFocusableInTouchMode(true); 50 | updateCardBackgroundColor(cardView, false); 51 | return new ViewHolder(cardView); 52 | } 53 | 54 | @Override 55 | public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { 56 | CardModel list = (CardModel) item; 57 | ImageCardView cardView = (ImageCardView) viewHolder.view; 58 | 59 | Log.d(TAG, "onBindViewHolder"); 60 | cardView.setTitleText(list.getTitle()); 61 | cardView.setContentText(list.getTitle()); 62 | cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); 63 | cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE); 64 | cardView.getMainImageView().setImageResource(R.drawable.barcode); 65 | } 66 | 67 | @Override 68 | public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { 69 | Log.d(TAG, "onUnbindViewHolder"); 70 | ImageCardView cardView = (ImageCardView) viewHolder.view; 71 | // Remove references to images so that the garbage collector can free up memory 72 | cardView.setBadgeImage(null); 73 | cardView.setMainImage(null); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/function/FunctionCardPresenter.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.function; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.support.v17.leanback.widget.ImageCardView; 5 | import android.support.v17.leanback.widget.Presenter; 6 | import android.util.Log; 7 | import android.util.TypedValue; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.tan.mytvlauncher.R; 13 | import com.tan.mytvlauncher.app.AppModel; 14 | 15 | /** 16 | * Created by t1569 on 2017/9/22. 17 | */ 18 | 19 | public class FunctionCardPresenter extends Presenter { 20 | private static final String TAG = "FunctionCardPresenter"; 21 | 22 | private static int CARD_WIDTH = 313; 23 | private static int CARD_HEIGHT = 176; 24 | private static int sSelectedBackgroundColor; 25 | private static int sDefaultBackgroundColor; 26 | private Drawable mDefaultCardImage; 27 | 28 | private static void updateCardBackgroundColor(ImageCardView view, boolean selected) { 29 | int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor; 30 | // Both background colors should be set because the view's background is temporarily visible 31 | // during animations. 32 | view.setBackgroundColor(color); 33 | view.findViewById(R.id.info_field).setBackgroundColor(color); 34 | } 35 | 36 | @Override 37 | public ViewHolder onCreateViewHolder(ViewGroup parent) { 38 | Log.d(TAG, "onCreateViewHolder"); 39 | 40 | sDefaultBackgroundColor = parent.getResources().getColor(R.color.default_background); 41 | sSelectedBackgroundColor = parent.getResources().getColor(R.color.detail_background); 42 | 43 | ImageCardView cardView = new ImageCardView(parent.getContext()) { 44 | @Override 45 | public void setSelected(boolean selected) { 46 | updateCardBackgroundColor(this, selected); 47 | super.setSelected(selected); 48 | } 49 | }; 50 | 51 | cardView.setFocusable(true); 52 | cardView.setFocusableInTouchMode(true); 53 | updateCardBackgroundColor(cardView, false); 54 | TextView title = (TextView) cardView.findViewById(R.id.title_text); 55 | title.setTextSize(TypedValue.COMPLEX_UNIT_SP, CARD_HEIGHT / 9); 56 | return new ViewHolder(cardView); 57 | } 58 | 59 | @Override 60 | public void onBindViewHolder(ViewHolder viewHolder, Object item) { 61 | FunctionModel functionModel = (FunctionModel) item; 62 | ImageCardView cardView = (ImageCardView) viewHolder.view; 63 | 64 | Log.d(TAG, "onBindViewHolder"); 65 | cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); 66 | cardView.setTitleText(functionModel.getName()); 67 | cardView.setMainImageScaleType(ImageView.ScaleType.FIT_CENTER); 68 | cardView.getMainImageView().setImageResource(functionModel.getIcon()); 69 | } 70 | 71 | @Override 72 | public void onUnbindViewHolder(ViewHolder viewHolder) { 73 | Log.d(TAG, "onUnbindViewHolder"); 74 | ImageCardView cardView = (ImageCardView) viewHolder.view; 75 | // Remove references to images so that the garbage collector can free up memory 76 | cardView.setBadgeImage(null); 77 | cardView.setMainImage(null); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/function/FunctionModel.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.function; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | import com.tan.mytvlauncher.R; 7 | import com.tan.mytvlauncher.app.AppUninstallActivity; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Created by t1569 on 2017/9/23. 14 | */ 15 | 16 | public class FunctionModel { 17 | private int icon; 18 | private String id; 19 | private String name; 20 | private Intent mIntent; 21 | 22 | public int getIcon() { 23 | return icon; 24 | } 25 | 26 | public void setIcon(int icon) { 27 | this.icon = icon; 28 | } 29 | 30 | public String getId() { 31 | return id; 32 | } 33 | 34 | public void setId(String id) { 35 | this.id = id; 36 | } 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public Intent getIntent() { 47 | return mIntent; 48 | } 49 | 50 | public void setIntent(Intent Intent) { 51 | this.mIntent = Intent; 52 | } 53 | 54 | public static List getFunctionList(Context context) { 55 | List functionModels = new ArrayList<>(); 56 | FunctionModel appUninstall = new FunctionModel(); 57 | appUninstall.setName(context.getString(R.string.appUninstall)); 58 | appUninstall.setIcon(R.drawable.ic_delete_forever_black_96dp); 59 | appUninstall.setIntent(new Intent(context, AppUninstallActivity.class)); 60 | 61 | functionModels.add(appUninstall); 62 | return functionModels; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/loader/AppItemLoader.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.loader; 2 | 3 | import android.content.AsyncTaskLoader; 4 | import android.content.Context; 5 | import android.content.Loader; 6 | import android.support.v17.leanback.widget.ArrayObjectAdapter; 7 | import android.support.v17.leanback.widget.HeaderItem; 8 | import android.support.v17.leanback.widget.ListRow; 9 | import android.util.Log; 10 | 11 | import com.tan.mytvlauncher.MainActivity; 12 | import com.tan.mytvlauncher.R; 13 | import com.tan.mytvlauncher.app.AppCardPresenter; 14 | import com.tan.mytvlauncher.app.AppDataManager; 15 | import com.tan.mytvlauncher.app.AppModel; 16 | import com.tan.mytvlauncher.card.CardModel; 17 | import com.tan.mytvlauncher.card.CardPresenter; 18 | import com.tan.mytvlauncher.function.FunctionCardPresenter; 19 | import com.tan.mytvlauncher.function.FunctionModel; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.Comparator; 24 | import java.util.List; 25 | 26 | /** 27 | * Created by t1569 on 2017/9/24. 28 | */ 29 | 30 | public class AppItemLoader extends AsyncTaskLoader> { 31 | private static final String TAG = AppItemLoader.class.getSimpleName(); 32 | private static int CARD_L_WIDTH = 435; 33 | private static int CARD_L_HEIGHT = 300; 34 | private ArrayList mAppModels; 35 | 36 | public AppItemLoader(Context context, ArrayList appModels) { 37 | 38 | super(context); 39 | this.mAppModels = appModels; 40 | } 41 | 42 | @Override 43 | protected void onStartLoading() { 44 | forceLoad(); 45 | } 46 | 47 | @Override 48 | public List loadInBackground() { 49 | List listRows = new ArrayList<>(); 50 | Log.d(TAG, "loadInBackground: " + mAppModels.size()); 51 | listRows.add(getUsedRow()); 52 | 53 | listRows.addAll(getAppRow()); 54 | listRows.add(getFunctionRow()); 55 | return listRows; 56 | } 57 | 58 | private ListRow getUsedRow() { 59 | ArrayObjectAdapter usedListRowAdapter = new ArrayObjectAdapter(new AppCardPresenter(CARD_L_WIDTH, CARD_L_HEIGHT)); 60 | ArrayList appModels = (ArrayList) mAppModels.clone(); 61 | Collections.sort(appModels, new Comparator() { 62 | public int compare(AppModel appModel1, AppModel appModel2) { 63 | return appModel2.getOpenCount() - appModel1.getOpenCount(); 64 | } 65 | }); 66 | for (int i = 0; i < 4; i++) { 67 | usedListRowAdapter.add(appModels.get(i)); 68 | } 69 | ListRow listRow = new ListRow(new HeaderItem(0, getContext().getString(R.string.title_used)), usedListRowAdapter); 70 | return listRow; 71 | } 72 | 73 | private ListRow getFunctionRow() { 74 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new FunctionCardPresenter()); 75 | List functionModels = FunctionModel.getFunctionList(getContext()); 76 | for (FunctionModel item : functionModels 77 | ) { 78 | listRowAdapter.add(item); 79 | } 80 | return new ListRow(new HeaderItem(0, getContext().getString(R.string.title_function)), listRowAdapter); 81 | } 82 | 83 | private List getAppRow() { 84 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new AppCardPresenter()); 85 | ArrayObjectAdapter listSysRowAdapter = new ArrayObjectAdapter(new AppCardPresenter()); 86 | for (AppModel appModel : mAppModels 87 | ) 88 | if (appModel.isSysApp()) listSysRowAdapter.add(appModel); 89 | else listRowAdapter.add(appModel); 90 | List listRows = new ArrayList<>(); 91 | listRows.add(new ListRow(new HeaderItem(0, getContext().getString(R.string.title_app)), listRowAdapter)); 92 | listRows.add(new ListRow(new HeaderItem(0, getContext().getString(R.string.title_sysapp)), listSysRowAdapter)); 93 | return listRows; 94 | } 95 | 96 | private ListRow[] getCardRow() { 97 | ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter()); 98 | 99 | for (CardModel carModel : CardModel.getCardModels() 100 | ) { 101 | listRowAdapter.add(carModel); 102 | } 103 | 104 | HeaderItem header = new HeaderItem(0, getContext().getString(R.string.title_used)); 105 | return new ListRow[]{new ListRow(header, listRowAdapter)}; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/util/SpinnerFragment.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.util; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.view.Gravity; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | import android.widget.ProgressBar; 12 | 13 | /** 14 | * Created by t1569 on 2017/9/24. 15 | */ 16 | 17 | public class SpinnerFragment extends Fragment { 18 | private static final String TAG = SpinnerFragment.class.getSimpleName(); 19 | private static final int SPINNER_WIDTH = 100; 20 | private static final int SPINNER_HEIGHT = 100; 21 | 22 | @Override 23 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 24 | ProgressBar progressBar = new ProgressBar(container.getContext()); 25 | if (container instanceof FrameLayout) { 26 | FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(SPINNER_WIDTH, SPINNER_HEIGHT, Gravity.CENTER); 27 | progressBar.setLayoutParams(layoutParams); 28 | } 29 | return progressBar; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/tan/mytvlauncher/util/Tools.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher.util; 2 | 3 | import android.bluetooth.BluetoothDevice; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.pm.PackageInfo; 7 | import android.content.pm.PackageManager; 8 | import android.content.pm.ResolveInfo; 9 | import android.os.Environment; 10 | import android.os.StatFs; 11 | import android.telephony.TelephonyManager; 12 | import android.util.Log; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.ListAdapter; 16 | import android.widget.ListView; 17 | import android.widget.Toast; 18 | 19 | import org.json.JSONException; 20 | import org.json.JSONObject; 21 | 22 | import java.io.File; 23 | import java.lang.reflect.Method; 24 | import java.text.ParseException; 25 | import java.text.SimpleDateFormat; 26 | import java.util.ArrayList; 27 | import java.util.Date; 28 | import java.util.List; 29 | import java.util.regex.Matcher; 30 | import java.util.regex.Pattern; 31 | 32 | public final class Tools { 33 | private static String TAG = "Tools"; 34 | 35 | private final static String[] hexDigits = {"0", "1", "2", "3", "4", "5", 36 | "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; 37 | 38 | private Tools() throws InstantiationException { 39 | throw new InstantiationException("This class is not created for instantiaation"); 40 | } 41 | 42 | public static String byteArrayToHexString(byte[] b) { 43 | StringBuffer resultSb = new StringBuffer(); 44 | for (int i = 0; i < b.length; i++) { 45 | resultSb.append(byteToHexString(b[i])); 46 | } 47 | return resultSb.toString(); 48 | } 49 | 50 | private static String byteToHexString(byte b) { 51 | int n = b; 52 | if (n < 0) 53 | n = 256 + n; 54 | int d1 = n / 16; 55 | int d2 = n % 16; 56 | return hexDigits[d1] + hexDigits[d2]; 57 | } 58 | 59 | /** 60 | * @param mobiles 61 | * @return 62 | */ 63 | public static boolean isMobileNO(String mobiles) { 64 | Pattern p = Pattern 65 | .compile("^((13[0-9])|(15[^4,\\D])|(18[0,1,3,5-9]))\\d{8}$"); 66 | Matcher m = p.matcher(mobiles); 67 | System.out.println(m.matches() + "-telnum-"); 68 | return m.matches(); 69 | } 70 | 71 | /** 72 | * @param expression 73 | * @param text 74 | * @return 75 | */ 76 | private static boolean matchingText(String expression, String text) { 77 | Pattern p = Pattern.compile(expression); 78 | Matcher m = p.matcher(text); 79 | return m.matches(); 80 | } 81 | 82 | /** 83 | * @param zipcode 84 | * @return 85 | */ 86 | public static boolean isZipcode(String zipcode) { 87 | Pattern p = Pattern.compile("[0-9]\\d{5}"); 88 | Matcher m = p.matcher(zipcode); 89 | System.out.println(m.matches() + "-zipcode-"); 90 | return m.matches(); 91 | } 92 | 93 | /** 94 | * @param email 95 | * @return 96 | */ 97 | public static boolean isValidEmail(String email) { 98 | Pattern p = Pattern 99 | .compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"); 100 | Matcher m = p.matcher(email); 101 | System.out.println(m.matches() + "-email-"); 102 | return m.matches(); 103 | } 104 | 105 | /** 106 | * @param telfix 107 | * @return 108 | */ 109 | public static boolean isTelfix(String telfix) { 110 | Pattern p = Pattern.compile("d{3}-d{8}|d{4}-d{7}"); 111 | Matcher m = p.matcher(telfix); 112 | System.out.println(m.matches() + "-telfix-"); 113 | return m.matches(); 114 | } 115 | 116 | /** 117 | * @param name 118 | * @return 119 | */ 120 | public static boolean isCorrectUserName(String name) { 121 | Pattern p = Pattern.compile("([A-Za-z0-9]){2,10}"); 122 | Matcher m = p.matcher(name); 123 | System.out.println(m.matches() + "-name-"); 124 | return m.matches(); 125 | } 126 | 127 | /** 128 | * @param pwd 129 | * @return 130 | */ 131 | public static boolean isCorrectUserPwd(String pwd) { 132 | Pattern p = Pattern.compile("\\w{6,18}"); 133 | Matcher m = p.matcher(pwd); 134 | System.out.println(m.matches() + "-pwd-"); 135 | return m.matches(); 136 | } 137 | 138 | /** 139 | * @return 140 | */ 141 | public static boolean hasSdcard() { 142 | String state = Environment.getExternalStorageState(); 143 | if (state.equals(Environment.MEDIA_MOUNTED)) { 144 | return true; 145 | } else { 146 | return false; 147 | } 148 | } 149 | 150 | /** 151 | * @param endTime 152 | * @param countDown 153 | * @return 剩余时间 154 | */ 155 | public static String calculationRemainTime(String endTime, long countDown) { 156 | 157 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 158 | try { 159 | Date now = new Date(System.currentTimeMillis());// ��ȡ��ǰʱ�� 160 | Date endData = df.parse(endTime); 161 | long l = endData.getTime() - countDown - now.getTime(); 162 | long day = l / (24 * 60 * 60 * 1000); 163 | long hour = l / (60 * 60 * 1000) - day * 24; 164 | long min = (l / (60 * 1000)) - day * 24 * 60 - hour * 60; 165 | long s = l / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60; 166 | return "ʣ��" + day + "��" + hour + "Сʱ" + min + "��" + s + "��"; 167 | } catch (ParseException e) { 168 | e.printStackTrace(); 169 | } 170 | return ""; 171 | } 172 | 173 | public static void showLongToast(Context act, String pMsg) { 174 | Toast toast = Toast.makeText(act, pMsg, Toast.LENGTH_LONG); 175 | toast.show(); 176 | } 177 | 178 | public static void showShortToast(Context act, String pMsg) { 179 | Toast toast = Toast.makeText(act, pMsg, Toast.LENGTH_SHORT); 180 | toast.show(); 181 | } 182 | 183 | /** 184 | * @param context 185 | * @return 186 | */ 187 | public static String getImeiCode(Context context) { 188 | TelephonyManager tm = (TelephonyManager) context 189 | .getSystemService(Context.TELEPHONY_SERVICE); 190 | return tm.getDeviceId(); 191 | } 192 | 193 | /** 194 | * @param listView 195 | * @author sunglasses 196 | * @category 计算listview高度 197 | */ 198 | public static void setListViewHeightBasedOnChildren(ListView listView) { 199 | ListAdapter listAdapter = listView.getAdapter(); 200 | if (listAdapter == null) { 201 | return; 202 | } 203 | 204 | int totalHeight = 0; 205 | for (int i = 0; i < listAdapter.getCount(); i++) { 206 | View listItem = listAdapter.getView(i, null, listView); 207 | listItem.measure(0, 0); 208 | totalHeight += listItem.getMeasuredHeight(); 209 | } 210 | 211 | ViewGroup.LayoutParams params = listView.getLayoutParams(); 212 | params.height = totalHeight 213 | + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 214 | listView.setLayoutParams(params); 215 | } 216 | 217 | public static PackageInfo getAPKVersionInfo(Context context, 218 | String packageName) { 219 | PackageManager packageManager = context.getPackageManager(); 220 | PackageInfo packInfo = null; 221 | try { 222 | packInfo = packageManager.getPackageInfo(packageName, 0); 223 | } catch (PackageManager.NameNotFoundException e) { 224 | e.printStackTrace(); 225 | } 226 | return packInfo; 227 | } 228 | 229 | /** 230 | * 得到sd卡剩余大小 231 | * 232 | * @return 233 | */ 234 | public static long getSDAvailableSize() { 235 | File path = Environment.getExternalStorageDirectory(); 236 | StatFs stat = new StatFs(path.getPath()); 237 | long blockSize = 0; 238 | long availableBlocks = 0; 239 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { 240 | blockSize = stat.getBlockSizeLong(); 241 | availableBlocks = stat.getAvailableBlocksLong(); 242 | } else { 243 | blockSize = stat.getBlockSize(); 244 | availableBlocks = stat.getAvailableBlocks(); 245 | } 246 | 247 | return blockSize * availableBlocks / 1024; 248 | } 249 | 250 | /** 251 | * 判断是否是json结构 252 | */ 253 | public static boolean isJson(String value) { 254 | try { 255 | new JSONObject(value); 256 | } catch (JSONException e) { 257 | return false; 258 | } 259 | return true; 260 | } 261 | 262 | public static List findActivitiesForPackage(Context context, String packageName) { 263 | final PackageManager packageManager = context.getPackageManager(); 264 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 265 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 266 | mainIntent.setPackage(packageName); 267 | final List apps = packageManager.queryIntentActivities(mainIntent, 0); 268 | return apps != null ? apps : new ArrayList(); 269 | } 270 | 271 | static public boolean removeBond(Class btClass, BluetoothDevice btDevice) throws Exception { 272 | Method removeBondMethod = btClass.getMethod("removeBond"); 273 | Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice); 274 | return returnValue.booleanValue(); 275 | } 276 | 277 | } 278 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/barcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/drawable/barcode.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete_black_96dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete_forever_black_96dp.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/item_focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/drawable/item_focus.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/pic_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/drawable/pic_default.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/sel_focus.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_app_uninstall.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 17 | 18 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_app_uninstall.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 25 | 26 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | #3d3d3d 7 | #ffaa3f 8 | #000000 9 | #DDDDDD 10 | #0096a6 11 | #ffaa3f 12 | #0096a6 13 | #30000000 14 | #30FF0000 15 | #00000000 16 | #AA000000 17 | #59000000 18 | #FFFFFF 19 | #AAFADCA7 20 | #FADCA7 21 | #EEFF41 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 简洁桌面 3 | 常用 4 | 应用 5 | 系统应用 6 | 应用卸载 7 | 应用卸载 8 | 功能 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/test/java/com/tan/mytvlauncher/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.tan.mytvlauncher; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.3.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Sep 22 19:35:40 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshots/Screenshot_20170924-003632.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/screenshots/Screenshot_20170924-003632.png -------------------------------------------------------------------------------- /screenshots/Screenshot_20170924-003642.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TAnsz/MyTvLauncher/7108fd97a887d9d7eb172f6b153d0bb681d72e03/screenshots/Screenshot_20170924-003642.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------