Android Launcher分析と修正5-HotSeat分析
24606 ワード
今日は主にLauncherの中のショートカットナビゲーションバー--HotSeatを分析します.一般的には携帯電話の下にこのナビゲーションバーがありますが、4.0のLauncherをタブレットの中に置いて実行すると、デフォルトはHotSeatがありません.ちょうど私のところの運行環境はタブレットに似ていて、システムのデフォルトはHotSeatを削除しました.方法、自分で方法を考えてそれを出すしかないので、今日は主にあなたのLauncherにHotSeatを追加する方法とHotSeatを分析して実現します.
Hotseatの構成はプロファイルによって制御されています.一般的には、Hotseatを必要としません.部品ファイルに書いておけばOKですが、Hotseatには横画面か縦画面かに注意するのが面倒なところがあります.デフォルトの縦画面の場合、Hotseatは画面の下にあり、横画面の場合、画面の右側にあります.Googleがなぜこのように設計したのか分からないが、横画面のために、もともと多くない縦方向の空間を占有しないのかもしれない.しかし、この設計はいくつかの横画面のタブレットやモバイルデバイスにとって、ユーザー体験があまりよくありません.
1、Hotseatプロファイル
次はHotseatのプロファイルを見てみましょう.Hotseatはworkspaceに属しているので、workspaceプロファイルの中で構成し、launcherを開く必要があります.xmlはhotseatの構成を見ることができます.これはすべてのlauncherではありません.xmlファイルにはhotseatプロパティがあります.例:layout-sw 600 dpフォルダの下のlauncher.xmlはデフォルトでhotseat構成がなく、これは大画面、タブレットなどの設定に使用されます.私のデバイスはちょうどこの構成を使用しています.
だからhotseatをlayout-sw 600 dpの下のlauncherに追加しましたxmlプロファイル:
ここでは、スクリーンの下に置くことを望んでいるので、縦スクリーンを使用するときのhotseat構成に注意してください.だからandroid:layout_gravity=
「bottom」もbottomに設定されています.hotseatのデフォルトは5つのボタンで、そのうちの1つはAllAppリストに入るボタンで、これはプログラムの中で設定します
(後述).他のデフォルトボタンはdefault_workspace.xmlで構成します.
default_workspaceの構成は、最初の文章で言ったように、ここをクリックすることができます.hotseatを構成するプロパティはworkspaceとは少し異なります.次に、異なるプロパティについて説明します. launcher:container:hotseatのデフォルトボタンを表す-101として識別する必要があります. launcher:screen:ボタンの位置を表し、0が最初の位置です.ALlAppボタンのデフォルトは2なので、screenが2のラベルはありません.
hotseatのデフォルトボタンを構成したら、hotseatを変更する必要があります.xmlの構成プロパティは正常に表示されます.以下はhotseatです.xmlの構成、
縦スクリーンを使用したときのhotseat構成です.
上のプロパティは、hotseatの表示効果に直接関係しているため、いくつか注意する必要があります.上で私はすでにいくつかの肝心な属性の大部分が私たちが一般的なコントロールを使うのと同じで、他のlauncher:XXXはlauncherが自分で定義した属性です.上にコメントがあります.注意すべきはlauncher:cellCountXとlauncher:cellCountYの2つの属性であり、これは横方向に垂直なhotseatに関係している.また、hotseatが複数行の複数列を定義できることもわかります.hotseatにはワークスペースと同じCellLayoutが含まれているからです.
Hotseatのプロパティの設定に加えて、hotseatが一部のスペースを占有しているため、workspaceは一部のスペース処理を空ける必要があります.例えば、元のワークスペースはhotseatに参加する前に5*3の設定で、hotseatに参加する必要がある場合は、ワークスペースは5*2の構成に変更するしかなく、縦方向の空間から1行の空間を出てhotseatに使用する必要があります.
2、Hotseat構造関数
ここまでは基本的に構成が設定されています.しかし、表示された効果は私たちが想像した結果ではありません.Hotseatの内部で横と縦のスクリーンを処理しているので、修正する必要があります.LauncherにはHotseatを専門に管理するクラスがあります:Hotseat.java .
次はJAvaの構築:
ここには大きな画面があるのか、小さな画面があるのかの判断に注意してください.これはタブレットシステムに属しているのか、一般的な携帯電話システムに属しているのかを判断するために使用されます.私のシステムは横画面でしか使えないので、
だから私は直接mIsLandscapeを小さなスクリーンに設定しました.Hotseatの多くはサイズのスクリーンを区別しているからです.小さなスクリーンの場合、縦方向を使用します
hotseatを構成すると、携帯電話システムに相当するhotseat効果が得られ、hotseatは画面の下に表示されます.
基本的に上記のいくつかの場所を変更すると、タブレット画面の下にhotseatが表示されます.Hotseatがどのように実現されているかを分析します.
3、Hotseatロードデータ
Hotseatロードデータは、AllAppボタンとその他のデフォルトボタンの2つの部分に分けることができます.次に、他のデフォルトボタンがどのようにロードされているかを見てみましょう.
デフォルトボタンロードはworkspaceのデフォルトデータロードと同様にLauncherModelでロードされます.
Hotseatはworkspaceのappタイプと同じように、
前回はLauncherが初期化データをロードするコードの一部を分析しましたが、Hotseatのデータロードはworkspaceの一般的なAPPショートカットロードと同じで、キューを共有してデータを保存していることがわかります.具体的なデータ・ロード・プロシージャの分析では、前の記事を参照できます.
4、Hotseatバインドデータ
hotseatバインドデータはworkspaceプロセスと基本的に同じで、以下はhotseatがバインドを開始するときに、Hotseat自身のメソッドを呼び出してデータを空にします.
上のプロファイルの分析では、HotseatにもCellLayoutが内部を管理する要素があると言いました.次に、データをバインドする方法を見てみましょう.
CellLayoutへ.ここでJAvaクラス内のaddInScreen()メソッド実装.
ここではHotseatキーの追加コードのみが与えられ、ソースコードを表示することができます.
5、Hotseat類
Hotseatクラスには実は多くありません.主に私たちが言った構造関数です.また、AllAPPボタンを設定する方法もあります.
Hotseatの他のいくつかの簡単な方法は、基本的にいくつかの属性を取得していますが、ここでは詳しく分析しません.
6、まとめ Hotseatも実はCellLayoutが中のすべてのデータを管理しています. のほとんどの構成は、XMLプロファイルの変更によって得ることができる. データのロードとバインドはworkspaceと基本的に一致しています.
今日はここまで、CellLayoutの分析について、次の記事でお話しします.
シリーズ記事:
Android Launcher分析と修正1-Launcherデフォルトインタフェース構成(default_workspace)
Android Launcher分析と修正2——Icon修正、インタフェースレイアウト調整、壁紙設定
Android Launcher分析と修正3-Launcher起動と初期化
Android Launcher分析と修正4-ロードデータの初期化
Edited by mythou
オリジナルブログ、転載は出典を明記してください:http://www.cnblogs.com/mythou/p/3172409.html
Hotseatの構成はプロファイルによって制御されています.一般的には、Hotseatを必要としません.部品ファイルに書いておけばOKですが、Hotseatには横画面か縦画面かに注意するのが面倒なところがあります.デフォルトの縦画面の場合、Hotseatは画面の下にあり、横画面の場合、画面の右側にあります.Googleがなぜこのように設計したのか分からないが、横画面のために、もともと多くない縦方向の空間を占有しないのかもしれない.しかし、この設計はいくつかの横画面のタブレットやモバイルデバイスにとって、ユーザー体験があまりよくありません.
1、Hotseatプロファイル
次はHotseatのプロファイルを見てみましょう.Hotseatはworkspaceに属しているので、workspaceプロファイルの中で構成し、launcherを開く必要があります.xmlはhotseatの構成を見ることができます.これはすべてのlauncherではありません.xmlファイルにはhotseatプロパティがあります.例:layout-sw 600 dpフォルダの下のlauncher.xmlはデフォルトでhotseat構成がなく、これは大画面、タブレットなどの設定に使用されます.私のデバイスはちょうどこの構成を使用しています.
だからhotseatをlayout-sw 600 dpの下のlauncherに追加しましたxmlプロファイル:
"@layout/hotseat"
android:id="@+id/hotseat"
android:layout_width="match_parent"
android:layout_height="@dimen/button_bar_height_plus_padding"
android:layout_gravity="bottom" />
ここでは、スクリーンの下に置くことを望んでいるので、縦スクリーンを使用するときのhotseat構成に注意してください.だからandroid:layout_gravity=
「bottom」もbottomに設定されています.hotseatのデフォルトは5つのボタンで、そのうちの1つはAllAppリストに入るボタンで、これはプログラムの中で設定します
(後述).他のデフォルトボタンはdefault_workspace.xmlで構成します.
<favorite
launcher:packageName="com.example.naviback"
launcher:className="com.example.naviback.MainActivity"
launcher:container="-101"
launcher:screen="0"
launcher:x="0"
launcher:y="0" />
<favorite
launcher:packageName="com.csr.dvd"
launcher:className="com.csr.dvd.LoadDVD"
launcher:container="-101"
launcher:screen="1"
launcher:x="1"
launcher:y="0" />
<favorite
launcher:packageName="com.apical.apicalradio"
launcher:className="com.apical.apicalradio.RadioMainActivity"
launcher:container="-101"
launcher:screen="3"
launcher:x="3"
launcher:y="0" />
<favorite
launcher:packageName="com.csr.BTApp"
launcher:className="com.csr.BTApp.CSRBluetoothDemoActivity"
launcher:container="-101"
launcher:screen="4"
launcher:x="4"
launcher:y="0" />
default_workspaceの構成は、最初の文章で言ったように、ここをクリックすることができます.hotseatを構成するプロパティはworkspaceとは少し異なります.次に、異なるプロパティについて説明します.
workspace , 。
hotseatのデフォルトボタンを構成したら、hotseatを変更する必要があります.xmlの構成プロパティは正常に表示されます.以下はhotseatです.xmlの構成、
縦スクリーンを使用したときのhotseat構成です.
<com.android.launcher2.Hotseat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:background="@drawable/hotseat_bg_panel"
launcher:cellCountX="5"
launcher:cellCountY="1">
<com.android.launcher2.CellLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:paddingLeft="150dp"
android:paddingRight="@dimen/button_bar_height_bottom_padding"
launcher:cellWidth="106dip"
launcher:cellHeight="106dip"
launcher:widthGap="25dp"
launcher:heightGap="@dimen/hotseat_height_gap"
launcher:maxGap="@dimen/workspace_max_gap" />
上のプロパティは、hotseatの表示効果に直接関係しているため、いくつか注意する必要があります.上で私はすでにいくつかの肝心な属性の大部分が私たちが一般的なコントロールを使うのと同じで、他のlauncher:XXXはlauncherが自分で定義した属性です.上にコメントがあります.注意すべきはlauncher:cellCountXとlauncher:cellCountYの2つの属性であり、これは横方向に垂直なhotseatに関係している.また、hotseatが複数行の複数列を定義できることもわかります.hotseatにはワークスペースと同じCellLayoutが含まれているからです.
Hotseatのプロパティの設定に加えて、hotseatが一部のスペースを占有しているため、workspaceは一部のスペース処理を空ける必要があります.例えば、元のワークスペースはhotseatに参加する前に5*3の設定で、hotseatに参加する必要がある場合は、ワークスペースは5*2の構成に変更するしかなく、縦方向の空間から1行の空間を出てhotseatに使用する必要があります.
2、Hotseat構造関数
ここまでは基本的に構成が設定されています.しかし、表示された効果は私たちが想像した結果ではありません.Hotseatの内部で横と縦のスクリーンを処理しているので、修正する必要があります.LauncherにはHotseatを専門に管理するクラスがあります:Hotseat.java .
次はJAvaの構築:
public Hotseat(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.Hotseat, defStyle, 0);
mCellCountX = a.getInt(R.styleable.Hotseat_cellCountX, -1);
mCellCountY = a.getInt(R.styleable.Hotseat_cellCountY, -1);
mIsLandscape = context.getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE;
// , hotseat
mIsLandscape = false;
}
ここには大きな画面があるのか、小さな画面があるのかの判断に注意してください.これはタブレットシステムに属しているのか、一般的な携帯電話システムに属しているのかを判断するために使用されます.私のシステムは横画面でしか使えないので、
だから私は直接mIsLandscapeを小さなスクリーンに設定しました.Hotseatの多くはサイズのスクリーンを区別しているからです.小さなスクリーンの場合、縦方向を使用します
hotseatを構成すると、携帯電話システムに相当するhotseat効果が得られ、hotseatは画面の下に表示されます.
基本的に上記のいくつかの場所を変更すると、タブレット画面の下にhotseatが表示されます.Hotseatがどのように実現されているかを分析します.
3、Hotseatロードデータ
Hotseatロードデータは、AllAppボタンとその他のデフォルトボタンの2つの部分に分けることができます.次に、他のデフォルトボタンがどのようにロードされているかを見てみましょう.
デフォルトボタンロードはworkspaceのデフォルトデータロードと同様にLauncherModelでロードされます.
Hotseatはworkspaceのappタイプと同じように、
private void loadWorkspace()
{
//........
switch (container)
{
case LauncherSettings.Favorites.CONTAINER_DESKTOP:
case LauncherSettings.Favorites.CONTAINER_HOTSEAT:
sWorkspaceItems.add(info);
break;
//........
}
前回はLauncherが初期化データをロードするコードの一部を分析しましたが、Hotseatのデータロードはworkspaceの一般的なAPPショートカットロードと同じで、キューを共有してデータを保存していることがわかります.具体的なデータ・ロード・プロシージャの分析では、前の記事を参照できます.
4、Hotseatバインドデータ
hotseatバインドデータはworkspaceプロセスと基本的に同じで、以下はhotseatがバインドを開始するときに、Hotseat自身のメソッドを呼び出してデータを空にします.
public void startBinding()
{
//..........
// Hotseat
if (mHotseat != null)
{
mHotseat.resetLayout();
}
}
上のプロファイルの分析では、HotseatにもCellLayoutが内部を管理する要素があると言いました.次に、データをバインドする方法を見てみましょう.
CellLayoutへ.ここでJAvaクラス内のaddInScreen()メソッド実装.
void addInScreen(View child, long container, int screen, int x, int y, int spanX, int spanY,
boolean insert) {
//...........
// CellLayout, Hotseat 。
final CellLayout layout;
if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
layout = mLauncher.getHotseat().getLayout();
child.setOnKeyListener(null);
// Hide folder title in the hotseat
if (child instanceof FolderIcon) {
((FolderIcon) child).setTextVisible(false);
}
if (screen < 0) {
screen = mLauncher.getHotseat().getOrderInHotseat(x, y);
} else {
// Note: We do this to ensure that the hotseat is always laid out in the orientation
// of the hotseat in order regardless of which orientation they were added
// child , true ,false
x = mLauncher.getHotseat().getCellXFromOrder(screen);
y = mLauncher.getHotseat().getCellYFromOrder(screen);
}
} else {
// Hotseat Folder,
if (child instanceof FolderIcon) {
((FolderIcon) child).setTextVisible(true);
}
layout = (CellLayout) getChildAt(screen);
child.setOnKeyListener(new IconKeyEventListener());
}
//.........
}
ここではHotseatキーの追加コードのみが与えられ、ソースコードを表示することができます.
5、Hotseat類
Hotseatクラスには実は多くありません.主に私たちが言った構造関数です.また、AllAPPボタンを設定する方法もあります.
void resetLayout() {
//
mContent.removeAllViewsInLayout();
// AllAPP , BubbleTextView
Context context = getContext();
LayoutInflater inflater = LayoutInflater.from(context);
BubbleTextView allAppsButton = (BubbleTextView)
inflater.inflate(R.layout.application, mContent, false);
// AllAPP , selector
allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null,
context.getResources().getDrawable(R.drawable.all_apps_button_icon), null, null);
// allAppsButton.setText(context.getString(R.string.all_apps_button_label));
allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
//allapp , Launcher
allAppsButton.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mLauncher != null &&
(event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
mLauncher.onTouchDownAllAppsButton(v);
}
return false;
}
});
//AllAPP , Launcher
allAppsButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(android.view.View v) {
if (mLauncher != null) {
mLauncher.onClickAllAppsButton(v);
}
}
});
// , AllAPP
int x = getCellXFromOrder(sAllAppsButtonRank);
int y = getCellYFromOrder(sAllAppsButtonRank);
Log.d("Mythou_Launcher", "Hotseat------>x="+x+" y="+y);
//Hotseat , allAppsButton CellLayout mythou
mContent.addViewToCellLayout(allAppsButton, -1, 0, new CellLayout.LayoutParams(x,y,1,1),
true);
}
Hotseatの他のいくつかの簡単な方法は、基本的にいくつかの属性を取得していますが、ここでは詳しく分析しません.
6、まとめ
今日はここまで、CellLayoutの分析について、次の記事でお話しします.
シリーズ記事:
Android Launcher分析と修正1-Launcherデフォルトインタフェース構成(default_workspace)
Android Launcher分析と修正2——Icon修正、インタフェースレイアウト調整、壁紙設定
Android Launcher分析と修正3-Launcher起動と初期化
Android Launcher分析と修正4-ロードデータの初期化
Edited by mythou
オリジナルブログ、転載は出典を明記してください:http://www.cnblogs.com/mythou/p/3172409.html