List of usage examples for android.widget TextView setMinimumHeight
@RemotableViewMethod public void setMinimumHeight(int minHeight)
From source file:com.yojiokisoft.yumekanow.activity.MainActivity.java
/** * ????????./*from w ww . java 2 s . c o m*/ * * @param width * @param height * @param title * @return */ private TextView getTabView(int width, int height, String title) { TextView view = new TextView(this); view.setMinimumWidth(width); view.setMinimumHeight(height); view.setGravity(Gravity.CENTER); view.setBackgroundResource(R.drawable.tab_indicator_holo); view.setText(title); return view; }
From source file:com.android.firewall.FirewallListPage.java
private TextView getTabView(int width, int height, String title) { TextView view = new TextView(this); view.setMinimumWidth(width);//ww w . j av a 2s.co m view.setMinimumHeight(height); view.setGravity(Gravity.CENTER); view.setBackgroundResource(R.drawable.tab_indicator_holo); view.setText(title); return view; }
From source file:net.etuldan.sparss.fragment.EntriesListFragment.java
@Override public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true); if (mEntriesCursorAdapter != null) { setListAdapter(mEntriesCursorAdapter); }/*from w w w . j ava 2s .c om*/ mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext())); if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) { final TextView header = new TextView(mListView.getContext()); header.setMinimumHeight(UiUtils.dpToPixel(70)); int footerPadding = UiUtils.dpToPixel(10); header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding); header.setText(R.string.tip_sentence); header.setGravity(Gravity.CENTER_VERTICAL); header.setCompoundDrawablePadding(UiUtils.dpToPixel(5)); header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_info_outline, 0, R.drawable.ic_cancel, 0); header.setClickable(true); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListView.removeHeaderView(header); PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false); } }); mListView.addHeaderView(header); } UiUtils.addEmptyFooterView(mListView, 90); mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button); mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { UiUtils.displayHideReadButtonAction(mListView.getContext()); return true; } }); UiUtils.updateHideReadButton(mHideReadButton); mSearchView = (SearchView) rootView.findViewById(R.id.searchView); if (savedInstanceState != null) { refreshUI(); // To hide/show the search bar } mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState @Override public void run() { mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); return false; } @Override public boolean onQueryTextChange(String s) { setData(EntryColumns.SEARCH_URI(s), true); return false; } }); } }); disableSwipe(); return rootView; }
From source file:org.opensilk.common.ui.widget.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.// ww w . ja va 2s . co m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setTextColor(mUnselectedTextColor); textView.setMinimumHeight( getResources().getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.tune.news.fragment.EntriesListFragment.java
@Override public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true); if (mEntriesCursorAdapter != null) { setListAdapter(mEntriesCursorAdapter); }//from w ww . jav a 2s.c o m mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setFastScrollEnabled(true); // mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext())); if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) { final TextView header = new TextView(mListView.getContext()); header.setMinimumHeight(UiUtils.dpToPixel(70)); int footerPadding = UiUtils.dpToPixel(10); header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding); header.setText(R.string.tip_sentence); header.setGravity(Gravity.CENTER_VERTICAL); header.setCompoundDrawablePadding(UiUtils.dpToPixel(5)); header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0, R.drawable.ic_action_cancel, 0); header.setClickable(true); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListView.removeHeaderView(header); PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false); } }); mListView.addHeaderView(header); } UiUtils.addEmptyFooterView(mListView, 90); mHideReadButton = (FloatingActionButton) rootView.findViewById(R.id.hide_read_button); mHideReadButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { UiUtils.displayHideReadButtonAction(mListView.getContext()); return true; } }); UiUtils.updateHideReadButton(mHideReadButton); mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn); mRefreshListBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mNewEntriesNumber = 0; mListDisplayDate = new Date().getTime(); refreshUI(); if (mUri != null) { restartLoaders(); } } }); mSearchView = (SearchView) rootView.findViewById(R.id.searchView); if (savedInstanceState != null) { refreshUI(); // To hide/show the search bar } mSearchView.post(new Runnable() { // Do this AFTER the text has been restored from saveInstanceState @Override public void run() { mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0); return false; } @Override public boolean onQueryTextChange(String s) { setData(EntryColumns.SEARCH_URI(s), true); return false; } }); } }); disableSwipe(); return rootView; }
From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java
@Override public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_entry_list, container, true); if (mEntriesCursorAdapter != null) { setListAdapter(mEntriesCursorAdapter); }/*w w w .j av a 2 s. co m*/ mListView = (ListView) rootView.findViewById(android.R.id.list); mListView.setOnTouchListener(new SwipeGestureListener(mListView.getContext())); if (PrefUtils.getBoolean(PrefUtils.DISPLAY_TIP, true)) { final TextView header = new TextView(mListView.getContext()); header.setMinimumHeight(UiUtils.dpToPixel(70)); int footerPadding = UiUtils.dpToPixel(10); header.setPadding(footerPadding, footerPadding, footerPadding, footerPadding); header.setText(R.string.tip_sentence); header.setGravity(Gravity.CENTER_VERTICAL); header.setCompoundDrawablePadding(UiUtils.dpToPixel(5)); header.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_about, 0, R.drawable.ic_action_cancel, 0); header.setClickable(true); header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mListView.removeHeaderView(header); PrefUtils.putBoolean(PrefUtils.DISPLAY_TIP, false); } }); mListView.addHeaderView(header); } UiUtils.addEmptyFooterView(mListView, 90); mRefreshListBtn = (Button) rootView.findViewById(R.id.refreshListBtn); mRefreshListBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mNewEntriesNumber = 0; mListDisplayDate = new Date().getTime(); refreshUI(); if (mCurrentUri != null) { restartLoaders(); } } }); disableSwipe(); return rootView; }
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }//from w w w . j a va2s . c o m builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:com.juick.android.MainActivity.java
public void updateNavigation() { navigationItems = new ArrayList<NavigationItem>(); List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values()); Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() { @Override/*from w w w . j av a 2s . c o m*/ public int compare(MicroBlog microBlog, MicroBlog microBlog2) { return microBlog.getPiority() - microBlog2.getPiority(); } }); for (MicroBlog blog : blogs) { blog.addNavigationSources(navigationItems, this); } navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread, R.drawable.navicon_juickadvanced, "msrcUnread") { @Override public void action() { final NavigationItem thisNi = this; final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true); pd.setTitle(R.string.navigationUnread); pd.setCancelable(true); pd.show(); UnreadSegmentsView.loadPeriods(MainActivity.this, new Utils.Function<Void, ArrayList<DatabaseService.Period>>() { @Override public Void apply(ArrayList<DatabaseService.Period> periods) { if (pd.isShowing()) { pd.cancel(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog alerDialog; if (periods.size() == 0) { alerDialog = builder.setTitle(getString(R.string.UnreadSegments)) .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments)) .setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }).create(); } else { UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView( MainActivity.this, periods); final int myIndex = navigationItems.indexOf(thisNi); alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment)) .setView(unreadSegmentsView).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }) .create(); unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() { @Override public void onPeriodClicked(DatabaseService.Period period) { alerDialog.dismiss(); int beforeMid = period.beforeMid; Bundle args = new Bundle(); args.putSerializable("messagesSource", new UnreadSegmentMessagesSource( getString(R.string.navigationUnread), MainActivity.this, period)); if (getSelectedNavigationIndex() != myIndex) { setSelectedNavigationItem(myIndex); } runDefaultFragmentWithBundle(args, thisNi); } }); } alerDialog.show(); restyleChildrenOrWidget(alerDialog.getWindow().getDecorView()); } return null; } }); return; } }); navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved, R.drawable.navicon_juickadvanced, "msrcSaved") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened, R.drawable.navicon_juickadvanced, "msrcRecentOpen") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented, R.drawable.navicon_juickadvanced, "msrcRecentComment") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined, R.drawable.navicon_juickadvanced, "msrcAllCombined") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedAllMessagesSource(MainActivity.this, "combined_all")); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllCombined(); break; } } }); navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined, R.drawable.navicon_juickadvanced, "msrcSubsCombined") { @Override public void action() { final NavigationItem thiz = this; new Thread("MessageSource Initializer") { @Override public void run() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedSubscriptionMessagesSource(MainActivity.this)); runOnUiThread(new Runnable() { @Override public void run() { runDefaultFragmentWithBundle(args, thiz); } }); } }.start(); final Bundle args = new Bundle(); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllSubs(); break; } } }); int index = 10000; final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE); for (NavigationItem navigationItem : navigationItems) { navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1); if (navigationItem.itemOrder == -1) { navigationItem.itemOrder = index; sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit(); } index++; } Collections.sort(navigationItems, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem lhs, NavigationItem rhs) { return lhs.itemOrder - rhs.itemOrder; // increasing } }); allNavigationItems = new ArrayList<NavigationItem>(navigationItems); final Iterator<NavigationItem> iterator = navigationItems.iterator(); while (iterator.hasNext()) { NavigationItem next = iterator.next(); if (next.sharedPrefsKey != null) { if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) { iterator.remove(); } } } sp_order.edit().commit(); // save final boolean compressedMenu = sp.getBoolean("compressedMenu", false); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final float finalMenuFontScale = menuFontScale; navigationList = (DragSortListView) findViewById(R.id.navigation_list); // adapter for old-style navigation final BaseAdapter navigationAdapter = new BaseAdapter() { @Override public int getCount() { return navigationItems.size(); } @Override public Object getItem(int position) { return navigationItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int layoutId = R.layout.simple_list_item_1_mine; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); if (parent instanceof Spinner) { tv.setTextSize(18 * finalMenuFontScale); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); } else { tv.setTextSize(22 * finalMenuFontScale); } tv.setText(getString(navigationItems.get(position).labelId)); if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } retval.setPressedListener(new PressableLinearLayout.PressedListener() { @Override public void onPressStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } @Override public void onSelectStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } }); MainActivity.restyleChildrenOrWidget(retval, false); return retval; } }; // adapter for new-style navigation final BaseAdapter navigationListAdapter = new BaseAdapter() { @Override public int getCount() { return getItems().size(); } private ArrayList<NavigationItem> getItems() { if (navigationList.isDragEnabled()) { return allNavigationItems; } else { return navigationItems; } } @Override public Object getItem(int position) { return getItems().get(position); } @Override public long getItemId(int position) { return position; } float textSize = -1; @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } if (textSize < 0) { View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView text = (TextView) inflate.findViewById(android.R.id.text1); textSize = text.getTextSize(); } final int layoutId = R.layout.navigation_list_item; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); final ArrayList<NavigationItem> items = getItems(); final NavigationItem theItem = items.get(position); tv.setText(getString(theItem.labelId)); ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button); menuButton.setFocusable(false); ArrayList<String> menuItems = theItem.getMenuItems(); menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { doNavigationItemMenu(theItem); } }); ImageView iv = (ImageView) retval.findViewById(android.R.id.icon); iv.setImageResource(theItem.imageId); retval.findViewById(R.id.draggable) .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE); retval.findViewById(R.id.checkbox).setVisibility( items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE); CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox); cb.setOnCheckedChangeListener(null); if (theItem.sharedPrefsKey != null) { cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey))); } cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit(); } }); int spacing = sp.getInt("navigation_spacing", 0); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing); retval.setPadding(0, spacing, 0, spacing); return retval; } }; ActionBar bar = getSupportActionBar(); updateActionBarMode(); navigationList.setDragEnabled(false); ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable); navigationList.setAdapter(navigationListAdapter); navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { setSelectedNavigationItem(position); closeNavigationMenu(true, false); } }); navigationList.setDropListener(new DragSortListView.DropListener() { @Override public void drop(int from, int to) { final NavigationItem item = allNavigationItems.remove(from); allNavigationItems.add(to, item); int index = 0; for (NavigationItem allNavigationItem : allNavigationItems) { if (allNavigationItem.itemOrder != index) { allNavigationItem.itemOrder = index; sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder) .commit(); } index++; } sp_order.edit().commit(); // save navigationListAdapter.notifyDataSetChanged(); //To change body of implemented methods use File | Settings | File Templates. } }); bar.setListNavigationCallbacks(navigationAdapter, this); final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button); navigationMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end : R.array.navigation_menu_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int spacing = sp.getInt("navigation_spacing", 0); switch (which) { case 0: if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } else { navigationList.setDragEnabled(true); } break; case 1: final Map<String, ?> all = sp_order.getAll(); for (String s : all.keySet()) { sp_order.edit().remove(s).commit(); } sp_order.edit().commit(); updateNavigation(); break; case 2: // wider sp.edit().putInt("navigation_spacing", spacing + 1).commit(); ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated(); break; case 3: // narrower if (spacing > 0) { sp.edit().putInt("navigation_spacing", spacing - 1).commit(); ((BaseAdapter) navigationList.getAdapter()) .notifyDataSetInvalidated(); } break; case 4: // logout from.. logoutFromSomeServices(); break; } navigationListAdapter.notifyDataSetChanged(); } }) .setCancelable(true).create().show(); } }); final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE); int restoredLastNavItem = spn.getInt("last_navigation", 0); if (restoredLastNavItem != 0) { NavigationItem allSources = null; for (int i = 0; i < navigationItems.size(); i++) { NavigationItem navigationItem = navigationItems.get(i); if (navigationItem.labelId == restoredLastNavItem) { lastNavigationItem = navigationItem; } if (navigationItem.labelId == R.string.navigationAll) { allSources = navigationItem; } } if (lastNavigationItem == null) { lastNavigationItem = allSources; // could be null if not configured } if (lastNavigationItem == null && navigationItems.size() > 0) { lastNavigationItem = navigationItems.get(0); // last default } if (lastNavigationItem != null) { restoreLastNavigationPosition(); lastNavigationItem.action(); } } }
From source file:edu.ptu.navpattern.tooltip.Tooltip.java
private View getContentView(final Builder builder) { GradientDrawable drawable = new GradientDrawable(); drawable.setColor(builder.mBackgroundColor); drawable.setCornerRadius(builder.mCornerRadius); LinearLayout vgContent = new LinearLayout(builder.mContext); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { vgContent.setBackground(drawable); } else {//from w w w . j a v a 2s . com //noinspection deprecation vgContent.setBackgroundDrawable(drawable); } int padding = (int) builder.mPadding; vgContent.setPadding(padding, padding, padding, padding); vgContent.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); textViewParams.gravity = Gravity.CENTER; textViewParams.topMargin = 1; vgContent.setLayoutParams(textViewParams); vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line)); vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); if (builder.itemText != null && builder.itemText.length > 0) { for (int i = 0; i < builder.itemText.length; i++) { TextView textView = new TextView(builder.mContext); textView.setText(builder.itemText[i]); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44); textView.setTextColor(0xffffffff); textView.setGravity(Gravity.CENTER_VERTICAL); if (builder.itemLogo != null && builder.itemLogo.length > i) { Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]); /// ??,??. // drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); // textView.setCompoundDrawables(drawableLeft, null, null, null); // textView.setCompoundDrawablePadding(4); // textView.setBackgroundDrawable(drawableLeft); LinearLayout linearLayout = new LinearLayout(builder.mContext); linearLayout.setMinimumHeight((int) dpToPx(44f)); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); ImageView icon = new ImageView(builder.mContext); icon.setImageDrawable(drawableLeft); linearLayout.addView(icon); linearLayout.addView(textView); vgContent.addView(linearLayout); final int position = i; linearLayout.setClickable(false); linearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0)); } }); } else { vgContent.addView(textView); final int position = i; textView.setClickable(false); textView.setMinimumHeight((int) dpToPx(44f)); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (builder.mOnItemClickListener != null) { builder.mOnItemClickListener.onClick(position); } mTouchListener.onTouch(v, null); } }); } } } mArrowView = new ImageView(builder.mContext); mArrowView.setImageDrawable(builder.mArrowDrawable); LinearLayout.LayoutParams arrowLayoutParams; if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight, 0); } else { arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth, 0); } arrowLayoutParams.gravity = Gravity.CENTER; mArrowView.setLayoutParams(arrowLayoutParams); mContentView = new LinearLayout(builder.mContext); mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); padding = (int) dpToPx(5); switch (mGravity) { case Gravity.START: mContentView.setPadding(0, 0, padding, 0); break; case Gravity.TOP: case Gravity.BOTTOM: mContentView.setPadding(padding, 0, padding, 0); break; case Gravity.END: mContentView.setPadding(padding, 0, 0, 0); break; } if (mGravity == Gravity.TOP || mGravity == Gravity.START) { mContentView.addView(vgContent); mContentView.addView(mArrowView); } else { mContentView.addView(mArrowView); mContentView.addView(vgContent); } if (builder.isCancelable || builder.isDismissOnClick) { mContentView.setOnTouchListener(mTouchListener); } return mContentView; }