編輯:關於Android編程
res/values/Config.xml0 在Launcher3 桌面,不管在哪一頁,按HOME 鍵,會回到默認頁。
1. 在Launcher3/src/com/android/launcher3/Launcher.java中
注釋updateGlobalIcons()方法調用,共兩處。
public View getQsbBar() {
if (mQsbBar == null) {
mQsbBar = mInflater.inflate(R.layout.search_bar, mSearchDropTargetBar, false);
- mSearchDropTargetBar.addView(mQsbBar);
}
+ mQsbBar.setVisibility(View.GONE);
return mQsbBar;
}
@Override
public void bindSearchablesChanged() { //注釋該方法內容
/* boolean searchVisible = updateGlobalSearchIcon();
boolean voiceVisible = updateVoiceSearchIcon(searchVisible);
if (mSearchDropTargetBar != null) {
mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible);
}
*/
}
2. 在Launcher3/src/com/android/launcher3/DynamicGrid.java中
// Layout the search bar
//注釋如下內容
/* View qsbBar = launcher.getQsbBar();
LayoutParams vglp = qsbBar.getLayoutParams();
vglp.width = LayoutParams.MATCH_PARENT;
vglp.height = LayoutParams.MATCH_PARENT;
qsbBar.setLayoutParams(vglp);
*/
3. 在Launcher3/res/values/dimens.xml中
- 48dp
+ 18dp
重新編譯後即可看到效果。
修改如下: 定位打/packages/apps/Launcher3/res/values/dimens.xml。3dp //修改這個可以調整search框距離頂部距離。500dp //search框的寬度,一般不需要調整。48dp //search框的高度,不要調整為0,刪除按鈕需要占用一部分空間。
添加res/values/arrays.xml:需要排序的應用:這裡的item 內容一定要填寫正確,否則會匹配不上,無法參與排序。src/com/android/launcher3/Utilities.java + import java.util.Arrays; + import java.util.List; + public static List - ComponentInfo{com.android.vending/com.android.vending.AssetBrowserActivity}
- ComponentInfo{com.android.browser/com.android.browser.BrowserActivity}
- ComponentInfo{com.android.settings/com.android.settings.Settings}
- ComponentInfo{com.android.camera2/com.android.camera.CameraLauncher}
- ComponentInfo{com.android.mms/com.android.mms.ui.ConversationList}
getAppsComponentName(final Context context) { + return Arrays.asList(context.getResources().getStringArray(R.array.apps_componentName)); + } src/com/android/launcher3/LauncherModel.java protected int mPreviousConfigMcc; + static List appArray = new ArrayList (); LauncherModel(LauncherAppState app, IconCache iconCache, AppFilter appFilter) { ...... mUserManager = UserManagerCompat.getInstance(context); + appArray = Utilities.getAppsComponentName(context); } 添加如下sortApps 方法:apps 按arrays.xml 排序,在原來的排序基礎上,將arrays.xml 配置的應用按順序排在前面。arrays.xml中沒有涉及到的應用,還是原來的順序。 public static final void sortApps(ArrayList apps) { int length = appArray.size(); List assignApps = new ArrayList(); for(int i=0;i -1 ;i--) { AppInfo app = assignApps.get(i); if(app != null){ apps.remove(app); apps.add(0, app); } } Log.d(TAG ,"The Apps List after Sort!"); } src/com/android/launcher3/AppsCustomizePagedView.java public void setApps(ArrayList list) { if (!LauncherAppState.isDisableAllApps()) { ...... SprdAppSortAddonStub.getInstance().sortApps(mApps); + LauncherModel.sortApps(mApps);//在原來排序的基礎上,再將arrays.xml中配置的應用按順序排在前面。 updatePageCountsAndInvalidateData(); } } private void addAppsWithoutInvalidate(ArrayList list) { ...... // SPRD: bug375932 2014-12-02 Feature customize app icon sort. SprdAppSortAddonStub.getInstance().sortApps(mApps); + LauncherModel.sortApps(mApps);//在原來排序的基礎上,再將arrays.xml中配置的應用按順序排在前面。 }
src/com/android/launcher3/DynamicGrid.java
選擇哪個default_workspace 和public DynamicGrid(Context context, Resources resources,int minWidthPx, int minHeightPx, int widthPx, int heightPx, int awPx, int ahPx)中的minWidthPx 和minHeightPx 以及該方法中創建的deviceProfiles 列表關。
minWidthPx 、minHeightPx 值轉換為dpi之後 ,deviceProfiles 列表與其進行比較,選擇與當前屏幕大小最接近的deviceProfiles 的default_workSpace作為最終Home界面使用的default_workspace。
詳細解釋如下:
src/com/android/launcher3/DynamicGrid.java中
1.deviceProfiles 列表如下:
deviceProfiles.add(new DeviceProfile("Super Short Stubby",
255, 300, 2, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Shorter Stubby",
255, 400, 3, 3, 48, 13, (hasAA ? 3 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Short Stubby",
275, 420, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Stubby",
255, 450, 3, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus S",
296, 491.33f, 4, 4, 48, 13, (hasAA ? 5 : 5), 48, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus 4",
335, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Nexus 5",
359, 567, 4, 4, DEFAULT_ICON_SIZE_DP, 13, (hasAA ? 5 : 5), 56, R.xml.default_workspace_4x4));
deviceProfiles.add(new DeviceProfile("Large Phone",
406, 694, 5, 5, 64, 14.4f, 5, 56, R.xml.default_workspace_5x5));
// The tablet profile is odd in that the landscape orientation
// also includes the nav bar on the side
deviceProfiles.add(new DeviceProfile("Nexus 7",
575, 904, 5, 6, 72, 14.4f, 7, 60, R.xml.default_workspace_5x6));
// Larger tablet profiles always have system bars on the top & bottom
deviceProfiles.add(new DeviceProfile("Nexus 10",
727, 1207, 5, 6, 76, 14.4f, 7, 64, R.xml.default_workspace_5x6));
deviceProfiles.add(new DeviceProfile("20-inch Tablet",
1527, 2527, 7, 7, 100, 20, 7, 72, R.xml.default_workspace_4x4));
2.重新計算MinWidth 和MinHeigh 單位是dpi。
mMinWidth = dpiFromPx(minWidthPx, dm);
mMinHeight = dpiFromPx(minHeightPx, dm);
3.創建mProfile,mProfile.defaultLayoutId 就是最終Home界面使用的default_workspace 的id。
mProfile中的defaultLayoutId 是哪個default_workspace 見DeviceProfile.java。
mProfile = new DeviceProfile(context, deviceProfiles,
mMinWidth, mMinHeight,
widthPx, heightPx,
awPx, ahPx,
resources);
src/com/android/launcher3/DeviceProfile.java
DeviceProfile(Context context,
ArrayList profiles,
float minWidth, float minHeight,
int wPx, int hPx,
int awPx, int ahPx,
Resources res) { 方法中:
4.用屏幕寬高創建的點(PointF xy = new PointF(width, height))與 deviceProfiles中的w 和 h 創建的點(dimens = new PointF(widthDps, heightDps))進行比較,也就是從deviceProfiles 列表中找出和當前屏幕大小最接近的deviceProfiles。
DeviceProfile closestProfile = findClosestDeviceProfile(minWidth, minHeight, points);
......
5.采用和當前屏幕大小最接近的deviceProfiles的default_workspace
defaultLayoutId = closestProfile.defaultLayoutId;
在launcher/src/com/android/launcher3/IconCache.java中修改,
private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info, private CacheEntry cacheLocked(ComponentName componentName, ResolveInfo info,
HashMap
修改方案如下:
請定位到src/com/android/launcher3/LauncherClings.java文件:
class LauncherClings implements OnClickListener {
......
private static final String TAG_CROP_TOP_AND_SIDES = "crop_bg_top_and_sides
- private static final boolean DISABLE_CLINGS = false;
+ private static final boolean DISABLE_CLINGS = true;
預覽的時候,沒有做格式轉化,所以顯示正常!
在設置壁紙的時候,默認是采用jpeg格式轉換的,導致轉換後損耗了一些,設置壁紙後,某些對比度比較高的壁紙就顯示的模糊!
修改方案:
默認修改為采用png格式轉換!
android6.0之前的版本,請做如下修改:
定位到/packages/apps/Launcher3/的WallpaperCropActivity.java文件
1、String mOutputFormat = "jpg";//修改為"png"
2、
protected static String getFileExtension(String requestFormat) {
String outputFormat = (requestFormat == null)
? "jpg"//修改為"png"
: requestFormat;
outputFormat = outputFormat.toLowerCase();
return (outputFormat.equals("png") || outputFormat.equals("gif"))
? "png" // We don't support gif compression.
: "jpg";
}
android6.0的版本,請做如下修改:
定位到/packages/apps/Launcher3/WallpaperPicker/src/com/android/gallery3d/common/BitmapCropTask.java文件
if (crop.compress(CompressFormat.JPEG, DEFAULT_COMPRESS_QUALITY, tmpOut)) 修改為:
if (crop.compress(CompressFormat.PNG, DEFAULT_COMPRESS_QUALITY, tmpOut))
在6.0中,平台版本預置了一些壁紙資源,相關路徑如下: 資源文件在: packages/apps/Launcher3/WallpaperPicker/res/drawable-xhdpi/ 字串文件在: packages/apps/Launcher3/WallpaperPicker/res/values-nodpi/wallpapers.xml
Android GestureDetector手勢滑動使用實例講解
Gesture在 ViewGroup中使用GestureDetector類可以讓我們快速的處理手勢事件,如點擊,滑動等。 使用GestureDetector分三步: 1.
Android之NDK開發一第一個測試
前兩天研究了一下NDK開發,然而沒有成功。今天興趣盎然,再試試,不知道會不會成功,我將記錄我在學習過程中遇到的一些困難,以及成功後的效果。我當前的狀態是以及學習了一段時間
android中彈出輸入法,內容上移的問題
前言:有一天在寫代碼的時候,我想達到如下效果: AndroidManifest中的windowSoftInputMode屬性,我將其設置為adjustResize,正常來
2.3.1 存儲數據到data目錄中
當應用安裝到Android後,系統會根據每個應用的包名創建一個/data/data/包名/的文件夾,訪問自己包名下的目錄是不需要權限的,並且Android已經提供了非常簡