use of android.widget.TabWidget in project android_packages_apps_Launcher2 by CyanogenMod.
the class FocusHelper method handlePagedViewGridLayoutWidgetKeyEvent.
/**
* Handles key events in a PageViewExtendedLayout containing PagedViewWidgets.
*/
static boolean handlePagedViewGridLayoutWidgetKeyEvent(PagedViewWidget w, int keyCode, KeyEvent e) {
final PagedViewGridLayout parent = (PagedViewGridLayout) w.getParent();
final PagedView container = (PagedView) parent.getParent();
final TabHost tabHost = findTabHostParent(container);
final TabWidget tabs = tabHost.getTabWidget();
final int widgetIndex = parent.indexOfChild(w);
final int widgetCount = parent.getChildCount();
final int pageIndex = ((PagedView) container).indexToPage(container.indexOfChild(parent));
final int pageCount = container.getChildCount();
final int cellCountX = parent.getCellCountX();
final int cellCountY = parent.getCellCountY();
final int x = widgetIndex % cellCountX;
final int y = widgetIndex / cellCountX;
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
ViewGroup newParent = null;
// Now that we load items in the bg asynchronously, we can't just focus
// child siblings willy-nilly
View child = null;
boolean wasHandled = false;
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (handleKeyEvent) {
// Select the previous widget or the last widget on the previous page
if (widgetIndex > 0) {
parent.getChildAt(widgetIndex - 1).requestFocus();
} else {
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
child = newParent.getChildAt(newParent.getChildCount() - 1);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
// Select the next widget or the first widget on the next page
if (widgetIndex < (widgetCount - 1)) {
parent.getChildAt(widgetIndex + 1).requestFocus();
} else {
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
child = newParent.getChildAt(0);
if (child != null)
child.requestFocus();
}
}
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_UP:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise select the tab bar
if (y > 0) {
int newWidgetIndex = ((y - 1) * cellCountX) + x;
child = parent.getChildAt(newWidgetIndex);
if (child != null)
child.requestFocus();
} else {
tabs.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) {
// Select the closest icon in the previous row, otherwise do nothing
if (y < (cellCountY - 1)) {
int newWidgetIndex = Math.min(widgetCount - 1, ((y + 1) * cellCountX) + x);
child = parent.getChildAt(newWidgetIndex);
if (child != null)
child.requestFocus();
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
if (handleKeyEvent) {
// Simulate a click on the widget
View.OnClickListener clickListener = (View.OnClickListener) container;
clickListener.onClick(w);
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_UP:
if (handleKeyEvent) {
// if there is no previous page
if (pageIndex > 0) {
newParent = getAppsCustomizePage(container, pageIndex - 1);
if (newParent != null) {
child = newParent.getChildAt(0);
}
} else {
child = parent.getChildAt(0);
}
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_PAGE_DOWN:
if (handleKeyEvent) {
// if there is no next page
if (pageIndex < (pageCount - 1)) {
newParent = getAppsCustomizePage(container, pageIndex + 1);
if (newParent != null) {
child = newParent.getChildAt(0);
}
} else {
child = parent.getChildAt(widgetCount - 1);
}
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_HOME:
if (handleKeyEvent) {
// Select the first item on this page
child = parent.getChildAt(0);
if (child != null)
child.requestFocus();
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_MOVE_END:
if (handleKeyEvent) {
// Select the last item on this page
parent.getChildAt(widgetCount - 1).requestFocus();
}
wasHandled = true;
break;
default:
break;
}
return wasHandled;
}
use of android.widget.TabWidget in project iNaturalistAndroid by inaturalist.
the class ObservationViewerActivity method refreshFavorites.
private void refreshFavorites() {
SharedPreferences pref = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
final String username = pref.getString("username", null);
TabWidget tabWidget = mTabHost.getTabWidget();
if ((mFavorites == null) || (mFavorites.size() == 0)) {
((TextView) tabWidget.getChildAt(2).findViewById(R.id.count)).setVisibility(View.GONE);
} else {
((TextView) tabWidget.getChildAt(2).findViewById(R.id.count)).setVisibility(View.VISIBLE);
((TextView) tabWidget.getChildAt(2).findViewById(R.id.count)).setText(String.valueOf(mFavorites.size()));
}
if (username == null) {
// Not logged in
mAddFavorite.setVisibility(View.GONE);
mLoginToAddFave.setVisibility(View.VISIBLE);
mFavesLoginSignUpButtons.setVisibility(View.VISIBLE);
mLoadingFavs.setVisibility(View.GONE);
mFavoritesList.setVisibility(View.GONE);
mNoFavsMessage.setVisibility(View.GONE);
mSyncToAddFave.setVisibility(View.GONE);
return;
}
if (mObservation.id == null) {
// Observation not synced
mSyncToAddFave.setVisibility(View.VISIBLE);
mLoginToAddFave.setVisibility(View.GONE);
mFavesLoginSignUpButtons.setVisibility(View.GONE);
mLoadingFavs.setVisibility(View.GONE);
mFavoritesList.setVisibility(View.GONE);
mAddFavorite.setVisibility(View.GONE);
mRemoveFavorite.setVisibility(View.GONE);
mNoFavsMessage.setVisibility(View.GONE);
return;
}
mSyncToAddFave.setVisibility(View.GONE);
mLoginToAddFave.setVisibility(View.GONE);
mFavesLoginSignUpButtons.setVisibility(View.GONE);
if (mFavorites == null) {
// Still loading
mLoadingFavs.setVisibility(View.VISIBLE);
mFavoritesList.setVisibility(View.GONE);
mAddFavorite.setVisibility(View.GONE);
mRemoveFavorite.setVisibility(View.GONE);
mNoFavsMessage.setVisibility(View.GONE);
return;
}
mLoadingFavs.setVisibility(View.GONE);
mFavoritesList.setVisibility(View.VISIBLE);
if (mFavorites.size() == 0) {
mNoFavsMessage.setVisibility(View.VISIBLE);
} else {
mNoFavsMessage.setVisibility(View.GONE);
}
mFavIndex = getFavoritedByUsername(username);
if (mFavIndex > -1) {
// User has favorited the observation
mAddFavorite.setVisibility(View.GONE);
mRemoveFavorite.setVisibility(View.VISIBLE);
} else {
mAddFavorite.setVisibility(View.VISIBLE);
mRemoveFavorite.setVisibility(View.GONE);
}
mFavoritesAdapter = new FavoritesAdapter(this, mFavorites);
mFavoritesList.setAdapter(mFavoritesAdapter);
mRemoveFavorite.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_UNFAVE);
Intent serviceIntent = new Intent(INaturalistService.ACTION_REMOVE_FAVORITE, null, ObservationViewerActivity.this, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, mObservation.id);
startService(serviceIntent);
mFavIndex = getFavoritedByUsername(username);
if (mFavIndex > -1)
mFavorites.remove(mFavIndex);
mFavoritesAdapter.notifyDataSetChanged();
mAddFavorite.setVisibility(View.VISIBLE);
mRemoveFavorite.setVisibility(View.GONE);
if (mFavorites.size() == 0) {
mNoFavsMessage.setVisibility(View.VISIBLE);
} else {
mNoFavsMessage.setVisibility(View.GONE);
}
}
});
mAddFavorite.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_OBS_FAVE);
Intent serviceIntent = new Intent(INaturalistService.ACTION_ADD_FAVORITE, null, ObservationViewerActivity.this, INaturalistService.class);
serviceIntent.putExtra(INaturalistService.OBSERVATION_ID, mObservation.id);
startService(serviceIntent);
SharedPreferences pref = getSharedPreferences("iNaturalistPreferences", MODE_PRIVATE);
String username = pref.getString("username", null);
String userIconUrl = pref.getString("user_icon_url", null);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
String dateStr = dateFormat.format(new Date());
BetterJSONObject newFav = new BetterJSONObject(String.format("{ \"user\": { \"login\": \"%s\", \"user_icon_url\": \"%s\" }, \"created_at\": \"%s\" }", username, userIconUrl, dateStr));
mFavorites.add(newFav);
mFavoritesAdapter.notifyDataSetChanged();
mRemoveFavorite.setVisibility(View.VISIBLE);
mAddFavorite.setVisibility(View.GONE);
if (mFavorites.size() == 0) {
mNoFavsMessage.setVisibility(View.VISIBLE);
} else {
mNoFavsMessage.setVisibility(View.GONE);
}
}
});
}
use of android.widget.TabWidget in project iNaturalistAndroid by inaturalist.
the class ObservationViewerActivity method refreshTabs.
private void refreshTabs(String tag) {
mActiveTab = tag;
mInfoTabContainer.setVisibility(View.GONE);
mActivityTabContainer.setVisibility(View.GONE);
mFavoritesTabContainer.setVisibility(View.GONE);
TabWidget tabWidget = mTabHost.getTabWidget();
tabWidget.getChildAt(0).findViewById(R.id.bottom_line).setVisibility(View.GONE);
tabWidget.getChildAt(1).findViewById(R.id.bottom_line).setVisibility(View.GONE);
tabWidget.getChildAt(2).findViewById(R.id.bottom_line).setVisibility(View.GONE);
((ImageView) tabWidget.getChildAt(0).findViewById(R.id.tab_icon)).setColorFilter(Color.parseColor("#757575"));
((ImageView) tabWidget.getChildAt(1).findViewById(R.id.tab_icon)).setColorFilter(Color.parseColor("#757575"));
((ImageView) tabWidget.getChildAt(2).findViewById(R.id.tab_icon)).setColorFilter(Color.parseColor("#757575"));
((TextView) tabWidget.getChildAt(2).findViewById(R.id.count)).setTextColor(Color.parseColor("#757575"));
int i = 0;
if (tag.equals(VIEW_TYPE_INFO)) {
mInfoTabContainer.setVisibility(View.VISIBLE);
i = 0;
} else if (tag.equals(VIEW_TYPE_COMMENTS_IDS)) {
mActivityTabContainer.setVisibility(View.VISIBLE);
i = 1;
} else if (tag.equals(VIEW_TYPE_FAVS)) {
mFavoritesTabContainer.setVisibility(View.VISIBLE);
((TextView) tabWidget.getChildAt(2).findViewById(R.id.count)).setTextColor(getResources().getColor(R.color.inatapptheme_color));
i = 2;
}
tabWidget.getChildAt(i).findViewById(R.id.bottom_line).setVisibility(View.VISIBLE);
((ImageView) tabWidget.getChildAt(i).findViewById(R.id.tab_icon)).setColorFilter(getResources().getColor(R.color.inatapptheme_color));
}
use of android.widget.TabWidget in project iNaturalistAndroid by inaturalist.
the class ProjectsActivity method refreshTabs.
private void refreshTabs(int pos) {
TabWidget tabWidget = mTabHost.getTabWidget();
for (int i = 0; i < 3; i++) {
tabWidget.getChildAt(i).findViewById(R.id.bottom_line).setVisibility(View.GONE);
((TextView) tabWidget.getChildAt(i).findViewById(R.id.tab_title)).setTextColor(Color.parseColor("#84000000"));
}
tabWidget.getChildAt(pos).findViewById(R.id.bottom_line).setVisibility(View.VISIBLE);
((TextView) tabWidget.getChildAt(pos).findViewById(R.id.tab_title)).setTextColor(Color.parseColor("#000000"));
}
use of android.widget.TabWidget in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class EmojiPalettesView method onFinishInflate.
@Override
protected void onFinishInflate() {
mTabHost = (TabHost) findViewById(R.id.emoji_category_tabhost);
mTabHost.setup();
for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) {
addTab(mTabHost, properties.mCategoryId);
}
mTabHost.setOnTabChangedListener(this);
final TabWidget tabWidget = mTabHost.getTabWidget();
tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
if (mCategoryIndicatorEnabled) {
// On TabWidget's strip, what looks like an indicator is actually a background.
// And what looks like a background are actually left and right drawables.
tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
}
mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);
mEmojiPager = (ViewPager) findViewById(R.id.emoji_keyboard_pager);
mEmojiPager.setAdapter(mEmojiPalettesAdapter);
mEmojiPager.setOnPageChangeListener(this);
mEmojiPager.setOffscreenPageLimit(0);
mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
mEmojiLayoutParams.setPagerProperties(mEmojiPager);
mEmojiCategoryPageIndicatorView = (EmojiCategoryPageIndicatorView) findViewById(R.id.emoji_category_page_id_view);
mEmojiCategoryPageIndicatorView.setColors(mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);
setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true);
final LinearLayout actionBar = (LinearLayout) findViewById(R.id.emoji_action_bar);
mEmojiLayoutParams.setActionBarProperties(actionBar);
// deleteKey depends only on OnTouchListener.
mDeleteKey = (ImageButton) findViewById(R.id.emoji_keyboard_delete);
mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
mDeleteKey.setTag(Constants.CODE_DELETE);
mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
// {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
// {@link View.OnTouchListener} is used as the trigger of key-press, while
// {@link View.OnClickListener} is used as the trigger of key-release which does not occur
// if the event is canceled by moving off the finger from the view.
// The text on alphabet keys are set at
// {@link #startEmojiPalettes(String,int,float,Typeface)}.
mAlphabetKeyLeft = (TextView) findViewById(R.id.emoji_keyboard_alphabet_left);
mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyLeft.setOnTouchListener(this);
mAlphabetKeyLeft.setOnClickListener(this);
mAlphabetKeyRight = (TextView) findViewById(R.id.emoji_keyboard_alphabet_right);
mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyRight.setOnTouchListener(this);
mAlphabetKeyRight.setOnClickListener(this);
mSpacebar = findViewById(R.id.emoji_keyboard_space);
mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
mSpacebar.setTag(Constants.CODE_SPACE);
mSpacebar.setOnTouchListener(this);
mSpacebar.setOnClickListener(this);
mEmojiLayoutParams.setKeyProperties(mSpacebar);
mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
Aggregations