List of usage examples for android.widget FrameLayout FrameLayout
public FrameLayout(@NonNull Context context)
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataSource.createIcons(getResources()); try {//from w w w.j av a 2 s. c o m // ?? final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // ? ?? ? this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag"); // ?? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? . 2 ?? (1/1000s), 3 ?? (m)? ? locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this); //orientation sensor sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE); orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION); killOnError(); // ? ? requestWindowFeature(Window.FEATURE_NO_TITLE); // ? ? // ?? FrameLayout frameLayout = new FrameLayout(this); // ? ?, ? frameLayout.setMinimumWidth(3000); frameLayout.setPadding(10, 0, 10, 10); // ? ? ? ?? ? camScreen = new CameraSurface(this); augScreen = new AugmentedView(this); setContentView(camScreen); // ? ?? ? ? // ? ?? ? addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // ? ? ? ? ?. // ? ? ? ?? ? ? ? addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM)); topLayoutOnMixView = new TopLayoutOnMixView(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(topLayoutOnMixView.mainArView, params); // ? ? ? topLayoutOnMixView ? ? handleIntent(getIntent()); // ?? // ? ? ? if (!isInited) { mixContext = new MixContext(this); // ? ? // ? ? mixContext.downloadManager = new DownloadManager(mixContext); //? ? ? navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment); // ? ? ?? ? ? dWindow = new PaintScreen(); dataView = new DataView(mixContext); isInited = true; // true } if (mixContext.isActualLocation() == false) { Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show(); } } catch (Exception ex) { doError(ex); // ? ? } // ? IntentFilter naviBraodFilter = new IntentFilter(); naviBraodFilter.addAction("NAVI"); registerReceiver(naviRecevicer, naviBraodFilter); }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java
/** * viewid/*ww w .jav a2 s . c o m*/ * * @param index * @param opid */ public final void removeSubviewFromContainer(final int index, final String opid) { if (null == mBrwView || opid == null) { return; } ((EBrowserActivity) mContext).runOnUiThread(new Runnable() { @Override public void run() { EBrowserWindow mWindow = mBrwView.getBrowserWindow(); int count = mWindow.getChildCount(); for (int i = 0; i < count; i++) { View view = mWindow.getChildAt(i); if (view instanceof ContainerViewPager) { ContainerViewPager pager = (ContainerViewPager) view; if (opid.equals((String) pager.getContainerVO().getId())) { ContainerAdapter adapter = (ContainerAdapter) pager.getAdapter(); Vector<FrameLayout> views = adapter.getViewList(); if (index < views.size() && index >= 0) { adapter.destroyItem(pager, index, null); views.get(index).removeAllViews(); views.set(index, new FrameLayout(mContext)); } else { return; } adapter.setViewList(views); adapter.notifyDataSetChanged(); return; } //end equals opid } //end instanceof } //end for }// end run });// end runOnUI }
From source file:org.telegram.ui.DialogsActivity.java
@Override public View createView(final Context context) { searching = false;/*w w w . ja va 2 s .c o m*/ searchWas = false; AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { Theme.loadRecources(context); } }); ActionBarMenu menu = actionBar.createMenu(); if (!onlySelect && searchString == null) { passcodeItem = menu.addItem(1, R.drawable.lock_close); updatePasscodeButton(); } final ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; if (listView != null) { if (searchString != null) { listView.setEmptyView(searchEmptyView); progressView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); } if (!onlySelect) { floatingButton.setVisibility(View.GONE); } } updatePasscodeButton(); } @Override public boolean canCollapseSearch() { if (searchString != null) { finishFragment(); return false; } return true; } @Override public void onSearchCollapse() { searching = false; searchWas = false; if (listView != null) { searchEmptyView.setVisibility(View.GONE); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (!onlySelect) { floatingButton.setVisibility(View.VISIBLE); floatingHidden = true; floatingButton.setTranslationY(AndroidUtilities.dp(100)); hideFloatingButton(false); } if (listView.getAdapter() != dialogsAdapter) { listView.setAdapter(dialogsAdapter); dialogsAdapter.notifyDataSetChanged(); } } if (dialogsSearchAdapter != null) { dialogsSearchAdapter.searchDialogs(null); } updatePasscodeButton(); } @Override public void onTextChanged(EditText editText) { String text = editText.getText().toString(); if (text.length() != 0 || dialogsSearchAdapter != null && dialogsSearchAdapter.hasRecentRearch()) { searchWas = true; if (dialogsSearchAdapter != null && listView.getAdapter() != dialogsSearchAdapter) { listView.setAdapter(dialogsSearchAdapter); dialogsSearchAdapter.notifyDataSetChanged(); } if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) { emptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); searchEmptyView.showTextView(); listView.setEmptyView(searchEmptyView); } } if (dialogsSearchAdapter != null) { dialogsSearchAdapter.searchDialogs(text); } } }); item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search)); if (onlySelect) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat)); } else { if (searchString != null) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); } else { actionBar.setBackButtonDrawable(new MenuDrawable()); } if (BuildVars.DEBUG_VERSION) { actionBar.setTitle(LocaleController.getString("AppNameBeta", R.string.AppNameBeta)); } else { actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } } actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { if (onlySelect) { finishFragment(); } else if (parentLayout != null) { parentLayout.getDrawerLayoutContainer().openDrawer(false); } } else if (id == 1) { UserConfig.appLocked = !UserConfig.appLocked; UserConfig.saveConfig(false); updatePasscodeButton(); } } }); FrameLayout frameLayout = new FrameLayout(context); fragmentView = frameLayout; fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.chat_list_background)); listView = new RecyclerListView(context); listView.setVerticalScrollBarEnabled(true); listView.setItemAnimator(null); listView.setInstantClick(true); listView.setLayoutAnimation(null); listView.setTag(4); layoutManager = new LinearLayoutManager(context) { @Override public boolean supportsPredictiveItemAnimations() { return false; } }; layoutManager.setOrientation(LinearLayoutManager.VERTICAL); listView.setLayoutManager(layoutManager); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() { @Override public void onItemClick(View view, int position) { if (listView == null || listView.getAdapter() == null) { return; } long dialog_id = 0; int message_id = 0; RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsAdapter) { TLRPC.TL_dialog dialog = dialogsAdapter.getItem(position); if (dialog == null) { return; } dialog_id = dialog.id; } else if (adapter == dialogsSearchAdapter) { Object obj = dialogsSearchAdapter.getItem(position); if (obj instanceof TLRPC.User) { dialog_id = ((TLRPC.User) obj).id; if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.User> users = new ArrayList<>(); users.add((TLRPC.User) obj); MessagesController.getInstance().putUsers(users, false); MessagesStorage.getInstance().putUsersAndChats(users, null, false, true); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.User) obj); } } else if (obj instanceof TLRPC.Chat) { if (dialogsSearchAdapter.isGlobalSearch(position)) { ArrayList<TLRPC.Chat> chats = new ArrayList<>(); chats.add((TLRPC.Chat) obj); MessagesController.getInstance().putChats(chats, false); MessagesStorage.getInstance().putUsersAndChats(null, chats, false, true); } if (((TLRPC.Chat) obj).id > 0) { dialog_id = -((TLRPC.Chat) obj).id; } else { dialog_id = AndroidUtilities.makeBroadcastId(((TLRPC.Chat) obj).id); } if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.Chat) obj); } } else if (obj instanceof TLRPC.EncryptedChat) { dialog_id = ((long) ((TLRPC.EncryptedChat) obj).id) << 32; if (!onlySelect) { dialogsSearchAdapter.putRecentSearch(dialog_id, (TLRPC.EncryptedChat) obj); } } else if (obj instanceof MessageObject) { MessageObject messageObject = (MessageObject) obj; dialog_id = messageObject.getDialogId(); message_id = messageObject.getId(); dialogsSearchAdapter.addHashtagsFromMessage(dialogsSearchAdapter.getLastSearchString()); } else if (obj instanceof String) { actionBar.openSearchField((String) obj); } } if (dialog_id == 0) { return; } if (onlySelect) { didSelectResult(dialog_id, true, false); } else { Bundle args = new Bundle(); int lower_part = (int) dialog_id; int high_id = (int) (dialog_id >> 32); if (lower_part != 0) { if (high_id == 1) { args.putInt("chat_id", lower_part); } else { if (lower_part > 0) { args.putInt("user_id", lower_part); } else if (lower_part < 0) { if (message_id != 0) { TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part); if (chat != null && chat.migrated_to != null) { args.putInt("migrated_to", lower_part); lower_part = -chat.migrated_to.channel_id; } } args.putInt("chat_id", -lower_part); } } } else { args.putInt("enc_id", high_id); } if (message_id != 0) { args.putInt("message_id", message_id); } else { if (actionBar != null) { actionBar.closeSearchField(); } } if (AndroidUtilities.isTablet()) { if (openedDialogId == dialog_id && adapter != dialogsSearchAdapter) { return; } if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = dialog_id); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } }); listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() { @Override public boolean onItemClick(View view, int position) { if (onlySelect || searching && searchWas || getParentActivity() == null) { if (searchWas && searching || dialogsSearchAdapter.isRecentSearchDisplayed()) { RecyclerView.Adapter adapter = listView.getAdapter(); if (adapter == dialogsSearchAdapter) { Object item = dialogsSearchAdapter.getItem(position); if (item instanceof String || dialogsSearchAdapter.isRecentSearchDisplayed()) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch)); builder.setPositiveButton(LocaleController .getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (dialogsSearchAdapter.isRecentSearchDisplayed()) { dialogsSearchAdapter.clearRecentSearch(); } else { dialogsSearchAdapter.clearRecentHashtags(); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); return true; } } } return false; } TLRPC.TL_dialog dialog; ArrayList<TLRPC.TL_dialog> dialogs = getDialogsArray(); if (position < 0 || position >= dialogs.size()) { return false; } dialog = dialogs.get(position); selectedDialog = dialog.id; BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity()); int lower_id = (int) selectedDialog; int high_id = (int) (selectedDialog >> 32); if (DialogObject.isChannel(dialog)) { final TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id); CharSequence items[]; if (chat != null && chat.megagroup) { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu) : LocaleController.getString("DeleteMegaMenu", R.string.DeleteMegaMenu) }; } else { items = new CharSequence[] { LocaleController.getString("ClearHistoryCache", R.string.ClearHistoryCache), chat == null || !chat.creator ? LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu) : LocaleController.getString("ChannelDeleteMenu", R.string.ChannelDeleteMenu) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { if (chat != null && chat.megagroup) { builder.setMessage(LocaleController.getString("AreYouSureClearHistorySuper", R.string.AreYouSureClearHistorySuper)); } else { builder.setMessage(LocaleController.getString("AreYouSureClearHistoryChannel", R.string.AreYouSureClearHistoryChannel)); } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(selectedDialog, 2); } }); } else { if (chat != null && chat.megagroup) { if (!chat.creator) { builder.setMessage(LocaleController.getString("MegaLeaveAlert", R.string.MegaLeaveAlert)); } else { builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert)); } } else { if (chat == null || !chat.creator) { builder.setMessage(LocaleController.getString("ChannelLeaveAlert", R.string.ChannelLeaveAlert)); } else { builder.setMessage(LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, UserConfig.getCurrentUser(), null); if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } else { final boolean isChat = lower_id < 0 && high_id != 1; TLRPC.User user = null; if (!isChat && lower_id > 0 && high_id != 1) { user = MessagesController.getInstance().getUser(lower_id); } final boolean isBot = user != null && user.bot; builder.setItems( new CharSequence[] { LocaleController.getString("ClearHistory", R.string.ClearHistory), isChat ? LocaleController.getString("DeleteChat", R.string.DeleteChat) : isBot ? LocaleController.getString("DeleteAndStop", R.string.DeleteAndStop) : LocaleController.getString("Delete", R.string.Delete) }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (which == 0) { builder.setMessage(LocaleController.getString("AreYouSureClearHistory", R.string.AreYouSureClearHistory)); } else { if (isChat) { builder.setMessage(LocaleController.getString("AreYouSureDeleteAndExit", R.string.AreYouSureDeleteAndExit)); } else { builder.setMessage(LocaleController.getString( "AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat)); } } builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (which != 0) { if (isChat) { TLRPC.Chat currentChat = MessagesController .getInstance().getChat((int) -selectedDialog); if (currentChat != null && ChatObject.isNotInChat(currentChat)) { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } else { MessagesController.getInstance().deleteUserFromChat( (int) -selectedDialog, MessagesController.getInstance().getUser( UserConfig.getClientUserId()), null); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 0); } if (isBot) { MessagesController.getInstance() .blockUser((int) selectedDialog); } if (AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName( NotificationCenter.closeChats, selectedDialog); } } else { MessagesController.getInstance() .deleteDialog(selectedDialog, 1); } } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); showDialog(builder.create()); } return true; } }); searchEmptyView = new EmptyTextProgressView(context); searchEmptyView.setVisibility(View.GONE); searchEmptyView.setShowAtCenter(true); searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult)); frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView = new LinearLayout(context); emptyView.setOrientation(LinearLayout.VERTICAL); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER); frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoChats", R.string.NoChats)); textView.setTextColor(0xff959595); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); textView = new TextView(context); String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp); if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) { help = help.replace('\n', ' '); } textView.setText(help); textView.setTextColor(0xff959595); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); textView.setGravity(Gravity.CENTER); textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(8), 0); textView.setLineSpacing(AndroidUtilities.dp(2), 1); emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT)); progressView = new ProgressBar(context); progressView.setVisibility(View.GONE); frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); // TODO fab color floatingButton = new FloatingActionButton(context); floatingButton.setVisibility(onlySelect ? View.GONE : View.VISIBLE); //floatingButton.setScaleType(ImageView.ScaleType.CENTER); //floatingButton.setBackgroundResource(R.drawable.floating_states); floatingButton.setImageResource(R.drawable.floating_pencil); floatingButton.getDrawable().setTint(ContextCompat.getColor(context, R.color.fab)); if (Build.VERSION.SDK_INT >= 21) { /*StateListAnimator animator = new StateListAnimator(); animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200)); animator.addState(new int[]{}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200)); floatingButton.setStateListAnimator(animator); */ } floatingButton.setOutlineProvider(new ViewOutlineProvider() { @SuppressLint("NewApi") @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56)); } }); frameLayout.addView(floatingButton, LayoutHelper.createFrame(56, 56, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 14 : 0, 0, LocaleController.isRTL ? 0 : 14, 14)); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle args = new Bundle(); args.putBoolean("destroyAfterSelect", true); presentFragment(new ContactsActivity(args)); } }); listView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) { AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus()); } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = layoutManager.findFirstVisibleItemPosition(); int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1; int totalItemCount = recyclerView.getAdapter().getItemCount(); if (searching && searchWas) { if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) { dialogsSearchAdapter.loadMoreSearchMessages(); } return; } if (visibleItemCount > 0) { if (layoutManager.findLastVisibleItemPosition() >= getDialogsArray().size() - 10) { MessagesController.getInstance().loadDialogs(-1, 100, !MessagesController.getInstance().dialogsEndReached); } } if (floatingButton.getVisibility() != View.GONE) { final View topChild = recyclerView.getChildAt(0); int firstViewTop = 0; if (topChild != null) { firstViewTop = topChild.getTop(); } boolean goingDown; boolean changed = true; if (prevPosition == firstVisibleItem) { final int topDelta = prevTop - firstViewTop; goingDown = firstViewTop < prevTop; changed = Math.abs(topDelta) > 1; } else { goingDown = firstVisibleItem > prevPosition; } if (changed && scrollUpdated) { hideFloatingButton(goingDown); } prevPosition = firstVisibleItem; prevTop = firstViewTop; scrollUpdated = true; } } }); if (searchString == null) { dialogsAdapter = new DialogsAdapter(context, dialogsType); if (AndroidUtilities.isTablet() && openedDialogId != 0) { dialogsAdapter.setOpenedDialogId(openedDialogId); } listView.setAdapter(dialogsAdapter); } int type = 0; if (searchString != null) { type = 2; } else if (!onlySelect) { type = 1; } dialogsSearchAdapter = new DialogsSearchAdapter(context, type, dialogsType); dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.DialogsSearchAdapterDelegate() { @Override public void searchStateChanged(boolean search) { if (searching && searchWas && searchEmptyView != null) { if (search) { searchEmptyView.showProgress(); } else { searchEmptyView.showTextView(); } } } @Override public void didPressedOnSubDialog(int did) { if (onlySelect) { didSelectResult(did, true, false); } else { Bundle args = new Bundle(); if (did > 0) { args.putInt("user_id", did); } else { args.putInt("chat_id", -did); } if (actionBar != null) { actionBar.closeSearchField(); } if (AndroidUtilities.isTablet()) { if (dialogsAdapter != null) { dialogsAdapter.setOpenedDialogId(openedDialogId = did); updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG); } } if (searchString != null) { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); presentFragment(new ChatActivity(args)); } } else { if (MessagesController.checkCanOpenChat(args, DialogsActivity.this)) { presentFragment(new ChatActivity(args)); } } } } @Override public void needRemoveHint(final int did) { if (getParentActivity() == null) { return; } TLRPC.User user = MessagesController.getInstance().getUser(did); if (user == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatString("ChatHintsDelete", R.string.ChatHintsDelete, ContactsController.formatName(user.first_name, user.last_name))); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SearchQuery.removePeer(did); } }); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); } }); if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) { searchEmptyView.setVisibility(View.GONE); emptyView.setVisibility(View.GONE); listView.setEmptyView(progressView); } else { searchEmptyView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); listView.setEmptyView(emptyView); } if (searchString != null) { actionBar.openSearchField(searchString); } if (!onlySelect && dialogsType == 0) { frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0)); } return fragmentView; }
From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestUI.java
/** * Builds the UI for PaymentRequest./*from ww w . jav a 2s.c o m*/ * * @param activity The activity on top of which the UI should be displayed. * @param client The consumer of the PaymentRequest UI. * @param requestShipping Whether the UI should show the shipping address and option selection. * @param requestContact Whether the UI should show the email address and phone number * selection. * @param canAddCards Whether the UI should show the [+ADD CARD] button. This can be false, * for example, when the merchant does not accept credit cards, so * there's no point in adding cards within PaymentRequest UI. * @param title The title to show at the top of the UI. This can be, for example, the * <title> of the merchant website. If the string is too long for * UI, it elides at the end. * @param origin The origin (part of URL) to show under the title. For example, * "https://shop.momandpop.com". If the origin is too long for the UI, it * should elide according to: * https://www.chromium.org/Home/chromium-security/enamel#TOC-Eliding-Origin-Names-And-Hostnames */ public PaymentRequestUI(Activity activity, Client client, boolean requestShipping, boolean requestContact, boolean canAddCards, String title, String origin) { mContext = activity; mClient = client; mRequestShipping = requestShipping; mRequestContactDetails = requestContact; mAnimatorTranslation = activity.getResources().getDimensionPixelSize(R.dimen.payments_ui_translation); mErrorView = (PaymentRequestUiErrorView) LayoutInflater.from(mContext) .inflate(R.layout.payment_request_error, null); mErrorView.initialize(title, origin); mReadyToPayNotifierForTest = new NotifierForTest(new Runnable() { @Override public void run() { if (sObserverForTest != null && isAcceptingUserInput() && mPayButton.isEnabled()) { sObserverForTest.onPaymentRequestReadyToPay(PaymentRequestUI.this); } } }); // This callback will be fired if mIsClientCheckingSelection is true. mUpdateSectionsCallback = new Callback<PaymentInformation>() { @Override public void onResult(PaymentInformation result) { mIsClientCheckingSelection = false; updateOrderSummarySection(result.getShoppingCart()); if (mRequestShipping) { updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAddresses()); updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptions()); } if (mRequestContactDetails) { updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails()); } updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods()); if (mShippingAddressSectionInformation.getSelectedItem() == null) { expand(mShippingAddressSection); } else { expand(null); } updatePayButtonEnabled(); notifySelectionChecked(); } }; mRequestView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.payment_request, null); prepareRequestView(activity, title, origin, canAddCards); // To handle the specced animations, the dialog is entirely contained within a translucent // FrameLayout. This could eventually be converted to a real BottomSheetDialog, but that // requires exploration of how interactions would work when the dialog can be sent back and // forth between the peeking and expanded state. mFullContainer = new FrameLayout(mContext); mFullContainer.setBackgroundColor( ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.payments_ui_scrim)); FrameLayout.LayoutParams bottomSheetParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); bottomSheetParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; mFullContainer.addView(mRequestView, bottomSheetParams); mEditorView = new EditorView(activity, sObserverForTest); mCardEditorView = new EditorView(activity, sObserverForTest); // Set up the dialog. mDialog = new AlwaysDismissedDialog(activity, R.style.DialogWhenLarge); mDialog.setOnDismissListener(this); mDialog.addContentView(mFullContainer, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); Window dialogWindow = mDialog.getWindow(); dialogWindow.setGravity(Gravity.CENTER); dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); }
From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java
private View createRoot() { FrameLayout parent = new FrameLayout(getActivity()); parent.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); backgroundLayer = new View(getActivity()); backgroundLayer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); backgroundLayer.setBackgroundColor(Color.argb(136, 0, 0, 0)); backgroundLayer.setOnClickListener(new View.OnClickListener() { @Override// w w w. j av a 2 s. c om public void onClick(View v) { dismiss(); if (actionListener != null) { actionListener.onCancel(); } } }); sheetContainer = new LinearLayout(getActivity()); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.BOTTOM; sheetContainer.setLayoutParams(params); sheetContainer.setOrientation(LinearLayout.VERTICAL); sheetContainer.setPadding(dp2px(8), dp2px(8), dp2px(8), dp2px(8)); parent.setPadding(0, 0, 0, getNavBarHeight(getActivity())); parent.addView(backgroundLayer); parent.addView(sheetContainer); return parent; }
From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java
private void update() { final FragmentActivity activity = getActivity(); if (activity == null) return;/* w ww . j ava2s . com*/ if (mRootView == null) { //This can happen when update() is called by the parent fragment //after this fragment has been instantiated after an orientation change, //but before onCreateView() has been called. It's not a problem //because onCreateView() will call this method again after setting mRootView. //Log.error("QuestionFragment.update(): mRootView is null."); return; } //Wipe the question details, //to ensure that we don't have old question details if somethng goes wrong when we //try to get and show the correct question details. final TextView textViewTitle = (TextView) mRootView.findViewById(R.id.textViewTitle); if (textViewTitle == null) { Log.error("update(): textViewTitle is null."); return; } textViewTitle.setText(""); //Show the text: final TextView textViewText = (TextView) mRootView.findViewById(R.id.textViewText); if (textViewText == null) { Log.error("update(): textViewText is null."); return; } textViewText.setText(""); final TableLayout layoutAnswers = (TableLayout) mRootView.findViewById(R.id.layoutAnswers); if (layoutAnswers == null) { Log.error("update(): layoutAnswers is null."); return; } layoutAnswers.removeAllViews(); if (getSingleton() == null) { //The parent fragment's onSingletonInitialized has been called //but this fragment's onSingletonInitialized hasn't been called yet. //That's OK. update() will be called, indirectly, later by this fragment's onSingletonInitialized(). return; } final DecisionTree.Question question = getQuestion(); if (question == null) { Log.error("update(): question is null."); return; } //Show the title: textViewTitle.setText(question.getTitle()); //Show the text: textViewText.setText(question.getText()); layoutAnswers.setShrinkAllColumns(true); layoutAnswers.setStretchAllColumns(true); //Checkboxes: mCheckboxButtons.clear(); final int COL_COUNT = 4; int col = 1; int rows = 0; TableRow row = null; final LayoutInflater inflater = LayoutInflater.from(activity); for (final DecisionTree.Checkbox checkbox : question.getCheckboxes()) { //Start a new row if necessary: if (row == null) { row = addRowToTable(activity, layoutAnswers); rows++; } final ToggleButton button = (ToggleButton) inflater.inflate(R.layout.question_answer_checkbox, null); //Use just the highlighting (line, color, etc) to show that it's selected, //instead of On/Off, so we don't need a separate label. //TODO: Use the icon. See http://stackoverflow.com/questions/18598255/android-create-a-toggle-button-with-image-and-no-text //TODO: Avoid the highlight bar thing at the bottom being drawn over the text. final String text = checkbox.getText(); button.setText(text); button.setTextOn(text); button.setTextOff(text); insertButtonInRow(activity, row, button); final BitmapDrawable icon = getIcon(activity, checkbox); button.setCompoundDrawables(null, icon, null, null); mCheckboxButtons.put(checkbox.getId(), button); if (col < COL_COUNT) { col++; } else { col = 1; row = null; } } //Answers: for (final DecisionTree.Answer answer : question.getAnswers()) { //Start a new row if necessary: if (row == null) { row = addRowToTable(activity, layoutAnswers); rows++; } final Button button = createAnswerButton(activity, answer); insertButtonInRow(activity, row, button); final String questionId = question.getId(); final String answerId = answer.getId(); button.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onAnswerButtonClicked(questionId, answerId); } }); if (col < COL_COUNT) { col++; } else { col = 1; row = null; } } //Add empty remaining cells, to avoid the other cells from expanding to fill the space, //because we want them to line up with the same cells above and below. if ((row != null) && (rows > 1)) { final int remaining_in_row = COL_COUNT - col + 1; for (int i = 0; i < remaining_in_row; i++) { //TODO: We could use Space instead of FrameLayout when using API>14. final FrameLayout placeholder = new FrameLayout(activity); insertButtonInRow(activity, row, placeholder); } } if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { /* This wastes even more space to be even more consistent: //Make sure there are always at least 2 rows, //so we request roughly the same amount of space each time: if (rows < 2) { row = addRowToTable(activity, layoutAnswers); final DecisionTree.Answer answer = new DecisionTree.Answer("bogus ID", "bogus title", getArbitraryIconId(), null, 0); final Button button = createAnswerButton(activity, answer); button.setVisibility(View.INVISIBLE); //It won't be seen, but it's size will be used. insertButtonInRow(activity, row, button); } */ //This will be used in a later onLayout(), //so we will know the correct height at least during the second classification, mRootView.setRowsCountForMaxHeightExperienced(rows); //Try to keep the height consistent, to avoid the user seeing everything moving about. final int min = mRootView.getMaximumHeightExperienced(rows); if (min > 0) { mRootView.setMinimumHeight(min); } } else { //Ignore any previously-set minimum height, //to stop the portrait-mode's layout from affecting the layout-mode's layout: mRootView.setMinimumHeight(0); } }
From source file:foam.opensauces.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { try {//from w ww .j a v a 2 s.c om String type = arr.getString(0); //Log.i("starwisp","building started "+type); if (type.equals("build-fragment")) { String name = arr.getString(1); int ID = arr.getInt(2); Fragment fragment = ActivityManager.GetFragment(name); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); inner.setId(ID); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, fragment); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("linear-layout")) { LinearLayout v = new LinearLayout(ctx); v.setId(arr.getInt(1)); v.setOrientation(BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); //v.setPadding(2,2,2,2); JSONArray col = arr.getJSONArray(4); v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("draggable")) { final LinearLayout v = new LinearLayout(ctx); final int id = arr.getInt(1); v.setPadding(20, 20, 20, 20); v.setId(id); v.setOrientation(BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setClickable(true); v.setFocusable(true); JSONArray col = arr.getJSONArray(4); v.setBackgroundResource(R.drawable.draggable); GradientDrawable drawable = (GradientDrawable) v.getBackground(); final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)); drawable.setColor(colour); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface /* v.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View vv) { if (id!=99) { ClipData dragData = ClipData.newPlainText("simple text", ""+id); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp","start drag id "+vv.getId()); v.startDrag(dragData, myShadow, null, 0); v.setVisibility(View.GONE); return true; } return false; } }); */ // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN && id != 99) { // ClipData dragData = ClipData.newPlainText("simple text", ""+id); ClipData dragData = new ClipData( new ClipDescription(null, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }), new ClipData.Item("" + id)); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp", "start drag id " + vv.getId()); v.startDrag(dragData, myShadow, null, 0); v.setVisibility(View.GONE); return true; } return false; } }); v.setOnDragListener(new View.OnDragListener() { public boolean onDrag(View vv, DragEvent event) { final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // returns true to indicate that the View can accept the dragged data. return true; } else { // Returns false. During the current drag and drop operation, this View will // not receive events again until ACTION_DRAG_ENDED is sent. return false; } case DragEvent.ACTION_DRAG_ENTERED: { return true; } case DragEvent.ACTION_DRAG_LOCATION: return true; case DragEvent.ACTION_DRAG_EXITED: { return true; } case DragEvent.ACTION_DROP: { ClipData.Item item = event.getClipData().getItemAt(0); String dragData = item.getText().toString(); Log.i("starwisp", "Dragged view is " + dragData); int otherid = Integer.parseInt(dragData); View otherw = ctx.findViewById(otherid); Log.i("starwisp", "removing from parent " + ((View) otherw.getParent()).getId()); // check we are not adding to ourself if (id != otherid) { ((ViewManager) otherw.getParent()).removeView(otherw); Log.i("starwisp", "adding to " + id); v.addView(otherw); } otherw.setVisibility(View.VISIBLE); return true; } case DragEvent.ACTION_DRAG_ENDED: { if (event.getResult()) { } else { } ; return true; } // An unknown action type was received. default: Log.e("starwisp", "Unknown action type received by OnDragListener."); break; } ; return true; } }); return; } if (type.equals("frame-layout")) { FrameLayout v = new FrameLayout(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } /* if (type.equals("grid-layout")) { GridLayout v = new GridLayout(ctx); v.setId(arr.getInt(1)); v.setRowCount(arr.getInt(2)); //v.setColumnCount(arr.getInt(2)); v.setOrientation(BuildOrientation(arr.getString(3))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } return; } */ if (type.equals("scroll-view")) { HorizontalScrollView v = new HorizontalScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("scroll-view-vert")) { ScrollView v = new ScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("view-pager")) { ViewPager v = new ViewPager(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.setOffscreenPageLimit(3); final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } return null; } }); parent.addView(v); return; } if (type.equals("space")) { // Space v = new Space(ctx); (class not found runtime error??) TextView v = new TextView(ctx); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); } if (type.equals("image-view")) { ImageView v = new ImageView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); String image = arr.getString(2); if (image.startsWith("/")) { Bitmap bitmap = BitmapFactory.decodeFile(image); v.setImageBitmap(bitmap); } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } parent.addView(v); } if (type.equals("text-view")) { TextView v = new TextView(ctx); v.setId(arr.getInt(1)); v.setText(Html.fromHtml(arr.getString(2))); v.setTextSize(arr.getInt(3)); v.setMovementMethod(LinkMovementMethod.getInstance()); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setClickable(false); v.setEnabled(false); v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { return false; } }); if (arr.length() > 5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity) ctx).m_Typeface); parent.addView(v); } if (type.equals("debug-text-view")) { TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null); // v.setBackgroundResource(R.color.black); v.setId(arr.getInt(1)); // v.setText(Html.fromHtml(arr.getString(2))); // v.setTextColor(R.color.white); // v.setTextSize(arr.getInt(3)); // v.setMovementMethod(LinkMovementMethod.getInstance()); // v.setMaxLines(10); // v.setVerticalScrollBarEnabled(true); // v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); //v.setMovementMethod(new ScrollingMovementMethod()); /* if (arr.length()>5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/ parent.addView(v); } if (type.equals("web-view")) { WebView v = new WebView(ctx); v.setId(arr.getInt(1)); v.setVerticalScrollBarEnabled(false); v.loadData(arr.getString(2), "text/html", "utf-8"); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); parent.addView(v); } if (type.equals("edit-text")) { final EditText v = new EditText(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); String inputtype = arr.getString(4); if (inputtype.equals("text")) { //v.setInputType(InputType.TYPE_CLASS_TEXT); } else if (inputtype.equals("numeric")) { v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); } else if (inputtype.equals("email")) { v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); } v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); //v.setSingleLine(true); v.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\""); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); parent.addView(v); } if (type.equals("button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("toggle-button")) { ToggleButton v = new ToggleButton(ctx); if (arr.getString(5).equals("fancy")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null); } if (arr.getString(5).equals("yes")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null); } if (arr.getString(5).equals("maybe")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null); } if (arr.getString(5).equals("no")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null); } v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, v.getId(), arg); } }); parent.addView(v); } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); v.setId(arr.getInt(1)); v.setMax(arr.getInt(2)); v.setProgress(arr.getInt(2) / 2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); final String fn = arr.getString(4); v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar v, int a, boolean s) { CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a)); } public void onStartTrackingTouch(SeekBar v) { } public void onStopTrackingTouch(SeekBar v) { } }); parent.addView(v); } if (type.equals("spinner")) { Spinner v = new Spinner(ctx); final int wid = arr.getInt(1); v.setId(wid); final JSONArray items = arr.getJSONArray(2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { try { CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\""); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } } public void onNothingSelected(AdapterView<?> v) { } }); parent.addView(v); } if (type.equals("canvas")) { StarwispCanvas v = new StarwispCanvas(ctx); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.SetDrawList(arr.getJSONArray(3)); parent.addView(v); } if (type.equals("camera-preview")) { PictureTaker pt = new PictureTaker(); CameraPreview v = new CameraPreview(ctx, pt); final int wid = arr.getInt(1); v.setId(wid); // LinearLayout.LayoutParams lp = // new LinearLayout.LayoutParams(minWidth, minHeight, 1); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); // v.setLayoutParams(lp); parent.addView(v); } if (type.equals("button-grid")) { LinearLayout horiz = new LinearLayout(ctx); final int id = arr.getInt(1); final String buttontype = arr.getString(2); horiz.setId(id); horiz.setOrientation(LinearLayout.HORIZONTAL); parent.addView(horiz); int height = arr.getInt(3); int textsize = arr.getInt(4); LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5)); JSONArray buttons = arr.getJSONArray(6); int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } } } } catch (JSONException e) { Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString()); } //Log.i("starwisp","building ended"); }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
protected void updateMessageDetail(final boolean isUpdate) { T.UI();/*from www. j a va2 s . c o m*/ // Set sender avatar ImageView avatarImage = (ImageView) findViewById(R.id.avatar); String sender = mCurrentMessage.sender; setAvatar(avatarImage, sender); // Set sender name TextView senderView = (TextView) findViewById(R.id.sender); final String senderName = mFriendsPlugin.getName(sender); senderView.setText(senderName == null ? sender : senderName); // Set timestamp TextView timestampView = (TextView) findViewById(R.id.timestamp); timestampView.setText(TimeUtils.getDayTimeStr(this, mCurrentMessage.timestamp * 1000)); // Set clickable region on top to go to friends detail final RelativeLayout messageHeader = (RelativeLayout) findViewById(R.id.message_header); messageHeader.setOnClickListener(getFriendDetailOnClickListener(mCurrentMessage.sender)); messageHeader.setVisibility(View.VISIBLE); // Set message TextView messageView = (TextView) findViewById(R.id.message); WebView web = (WebView) findViewById(R.id.webview); FrameLayout flay = (FrameLayout) findViewById(R.id.message_details); Resources resources = getResources(); flay.setBackgroundColor(resources.getColor(R.color.mc_background)); boolean showBranded = false; int darkSchemeTextColor = resources.getColor(android.R.color.primary_text_dark); int lightSchemeTextColor = resources.getColor(android.R.color.primary_text_light); senderView.setTextColor(lightSchemeTextColor); timestampView.setTextColor(lightSchemeTextColor); BrandingResult br = null; if (!TextUtils.isEmptyOrWhitespace(mCurrentMessage.branding)) { boolean brandingAvailable = false; try { brandingAvailable = mMessagingPlugin.getBrandingMgr().isBrandingAvailable(mCurrentMessage.branding); } catch (BrandingFailureException e1) { L.d(e1); } try { if (brandingAvailable) { br = mMessagingPlugin.getBrandingMgr().prepareBranding(mCurrentMessage); WebSettings settings = web.getSettings(); settings.setJavaScriptEnabled(false); settings.setBlockNetworkImage(false); web.loadUrl("file://" + br.file.getAbsolutePath()); web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); if (br.color != null) { flay.setBackgroundColor(br.color); } if (!br.showHeader) { messageHeader.setVisibility(View.GONE); MarginLayoutParams mlp = (MarginLayoutParams) web.getLayoutParams(); mlp.setMargins(0, 0, 0, mlp.bottomMargin); } else if (br.scheme == ColorScheme.dark) { senderView.setTextColor(darkSchemeTextColor); timestampView.setTextColor(darkSchemeTextColor); } showBranded = true; } else { mMessagingPlugin.getBrandingMgr().queueGenericBranding(mCurrentMessage.branding); } } catch (BrandingFailureException e) { L.bug("Could not display message with branding: branding is available, but prepareBranding failed", e); } } if (showBranded) { web.setVisibility(View.VISIBLE); messageView.setVisibility(View.GONE); } else { web.setVisibility(View.GONE); messageView.setVisibility(View.VISIBLE); messageView.setText(mCurrentMessage.message); } // Add list of members who did not ack yet FlowLayout memberSummary = (FlowLayout) findViewById(R.id.member_summary); memberSummary.removeAllViews(); SortedSet<MemberStatusTO> memberSummarySet = new TreeSet<MemberStatusTO>(getMemberstatusComparator()); for (MemberStatusTO ms : mCurrentMessage.members) { if ((ms.status & MessagingPlugin.STATUS_ACKED) != MessagingPlugin.STATUS_ACKED && !ms.member.equals(mCurrentMessage.sender)) { memberSummarySet.add(ms); } } FlowLayout.LayoutParams flowLP = new FlowLayout.LayoutParams(2, 0); for (MemberStatusTO ms : memberSummarySet) { FrameLayout fl = new FrameLayout(this); fl.setLayoutParams(flowLP); memberSummary.addView(fl); fl.addView(createParticipantView(ms)); } memberSummary.setVisibility(memberSummarySet.size() < 2 ? View.GONE : View.VISIBLE); // Add members statuses final LinearLayout members = (LinearLayout) findViewById(R.id.members); members.removeAllViews(); final String myEmail = mService.getIdentityStore().getIdentity().getEmail(); boolean isMember = false; mSomebodyAnswered = false; for (MemberStatusTO ms : mCurrentMessage.members) { boolean showMember = true; View view = getLayoutInflater().inflate(R.layout.message_member_detail, null); // Set receiver avatar RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.avatar); rl.addView(createParticipantView(ms)); // Set receiver name TextView receiverView = (TextView) view.findViewById(R.id.receiver); final String memberName = mFriendsPlugin.getName(ms.member); receiverView.setText(memberName == null ? sender : memberName); // Set received timestamp TextView receivedView = (TextView) view.findViewById(R.id.received_timestamp); if ((ms.status & MessagingPlugin.STATUS_RECEIVED) == MessagingPlugin.STATUS_RECEIVED) { final String humanTime = TimeUtils.getDayTimeStr(this, ms.received_timestamp * 1000); if (ms.member.equals(mCurrentMessage.sender)) receivedView.setText(getString(R.string.sent_at, humanTime)); else receivedView.setText(getString(R.string.received_at, humanTime)); } else { receivedView.setText(R.string.not_yet_received); } // Set replied timestamp TextView repliedView = (TextView) view.findViewById(R.id.acked_timestamp); if ((ms.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED) { mSomebodyAnswered = true; String acked_timestamp = TimeUtils.getDayTimeStr(this, ms.acked_timestamp * 1000); if (ms.button_id != null) { ButtonTO button = null; for (ButtonTO b : mCurrentMessage.buttons) { if (b.id.equals(ms.button_id)) { button = b; break; } } if (button == null) { repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); } else { repliedView.setText(getString(R.string.replied_at, button.caption, acked_timestamp)); } } else { if (ms.custom_reply == null) { // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); } else repliedView.setText(getString(R.string.replied_at, ms.custom_reply, acked_timestamp)); } } else { repliedView.setText(R.string.not_yet_replied); showMember = !ms.member.equals(mCurrentMessage.sender); } if (br != null && br.scheme == ColorScheme.dark) { receiverView.setTextColor(darkSchemeTextColor); receivedView.setTextColor(darkSchemeTextColor); repliedView.setTextColor(darkSchemeTextColor); } else { receiverView.setTextColor(lightSchemeTextColor); receivedView.setTextColor(lightSchemeTextColor); repliedView.setTextColor(lightSchemeTextColor); } if (showMember) members.addView(view); isMember |= ms.member.equals(myEmail); } boolean isLocked = (mCurrentMessage.flags & MessagingPlugin.FLAG_LOCKED) == MessagingPlugin.FLAG_LOCKED; boolean canEdit = isMember && !isLocked; // Add attachments LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachment_layout); attachmentLayout.removeAllViews(); if (mCurrentMessage.attachments.length > 0) { attachmentLayout.setVisibility(View.VISIBLE); for (final AttachmentTO attachment : mCurrentMessage.attachments) { View v = getLayoutInflater().inflate(R.layout.attachment_item, null); ImageView attachment_image = (ImageView) v.findViewById(R.id.attachment_image); if (AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(attachment.content_type) || AttachmentViewerActivity.CONTENT_TYPE_PNG.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_img); } else if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_pdf); } else if (AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4 .equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_video); } else { attachment_image.setImageResource(R.drawable.attachment_unknown); L.d("attachment.content_type not known: " + attachment.content_type); } TextView attachment_text = (TextView) v.findViewById(R.id.attachment_text); attachment_text.setText(attachment.name); v.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String downloadUrlHash = mMessagingPlugin .attachmentDownloadUrlHash(attachment.download_url); File attachmentsDir; try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), null); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } boolean attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); if (!attachmentAvailable) { try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), mCurrentMessage.key); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); } if (!mService.getNetworkConnectivityManager().isConnected() && !attachmentAvailable) { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(R.string.no_internet_connection_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } if (IOUtils.shouldCheckExternalStorageAvailable()) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // Its all oke } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (!attachmentAvailable) { L.d("Unable to write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } else { L.d("Unable to read or write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } L.d("attachment.content_type: " + attachment.content_type); L.d("attachment.download_url: " + attachment.download_url); L.d("attachment.name: " + attachment.name); L.d("attachment.size: " + attachment.size); if (AttachmentViewerActivity.supportsContentType(attachment.content_type)) { Intent i = new Intent(ServiceMessageDetailActivity.this, AttachmentViewerActivity.class); i.putExtra("thread_key", mCurrentMessage.getThreadKey()); i.putExtra("message", mCurrentMessage.key); i.putExtra("content_type", attachment.content_type); i.putExtra("download_url", attachment.download_url); i.putExtra("name", attachment.name); i.putExtra("download_url_hash", downloadUrlHash); startActivity(i); } else { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(getString(R.string.attachment_can_not_be_displayed_in_your_version, getString(R.string.app_name))); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); attachmentLayout.addView(v); } } else { attachmentLayout.setVisibility(View.GONE); } LinearLayout widgetLayout = (LinearLayout) findViewById(R.id.widget_layout); if (mCurrentMessage.form == null) { widgetLayout.setVisibility(View.GONE); } else { widgetLayout.setVisibility(View.VISIBLE); widgetLayout.setEnabled(canEdit); displayWidget(widgetLayout, br); } // Add buttons TableLayout tableLayout = (TableLayout) findViewById(R.id.buttons); tableLayout.removeAllViews(); for (final ButtonTO button : mCurrentMessage.buttons) { addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.form == null && (mCurrentMessage.flags & MessagingPlugin.FLAG_ALLOW_DISMISS) == MessagingPlugin.FLAG_ALLOW_DISMISS) { ButtonTO button = new ButtonTO(); button.caption = "Roger that!"; addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.broadcast_type != null) { L.d("Show broadcast spam control"); final RelativeLayout broadcastSpamControl = (RelativeLayout) findViewById(R.id.broadcast_spam_control); View broadcastSpamControlBorder = findViewById(R.id.broadcast_spam_control_border); final View broadcastSpamControlDivider = findViewById(R.id.broadcast_spam_control_divider); final LinearLayout broadcastSpamControlTextContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_text_container); TextView broadcastSpamControlText = (TextView) findViewById(R.id.broadcast_spam_control_text); final LinearLayout broadcastSpamControlSettingsContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_settings_container); TextView broadcastSpamControlSettingsText = (TextView) findViewById( R.id.broadcast_spam_control_settings_text); TextView broadcastSpamControlIcon = (TextView) findViewById(R.id.broadcast_spam_control_icon); broadcastSpamControlIcon.setTypeface(mFontAwesomeTypeFace); broadcastSpamControlIcon.setText(R.string.fa_bell); final FriendBroadcastInfo fbi = mFriendsPlugin.getFriendBroadcastFlowForMfr(mCurrentMessage.sender); if (fbi == null) { L.bug("BroadcastData was null for: " + mCurrentMessage.sender); collapseDetails(DETAIL_SECTIONS); return; } broadcastSpamControl.setVisibility(View.VISIBLE); broadcastSpamControlSettingsContainer.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { L.d("goto broadcast settings"); PressMenuIconRequestTO request = new PressMenuIconRequestTO(); request.coords = fbi.coords; request.static_flow_hash = fbi.staticFlowHash; request.hashed_tag = fbi.hashedTag; request.generation = fbi.generation; request.service = mCurrentMessage.sender; mContext = "MENU_" + UUID.randomUUID().toString(); request.context = mContext; request.timestamp = System.currentTimeMillis() / 1000; showTransmitting(null); Map<String, Object> userInput = new HashMap<String, Object>(); userInput.put("request", request.toJSONMap()); userInput.put("func", "com.mobicage.api.services.pressMenuItem"); MessageFlowRun mfr = new MessageFlowRun(); mfr.staticFlowHash = fbi.staticFlowHash; try { JsMfr.executeMfr(mfr, userInput, mService, true); } catch (EmptyStaticFlowException ex) { completeTransmit(null); AlertDialog.Builder builder = new AlertDialog.Builder(ServiceMessageDetailActivity.this); builder.setMessage(ex.getMessage()); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } } }); UIUtils.showHint(this, mService, HINT_BROADCAST, R.string.hint_broadcast, mCurrentMessage.broadcast_type, mFriendsPlugin.getName(mCurrentMessage.sender)); broadcastSpamControlText .setText(getString(R.string.broadcast_subscribed_to, mCurrentMessage.broadcast_type)); broadcastSpamControlSettingsText.setText(fbi.label); int ligthAlpha = 180; int darkAlpha = 70; int alpha = ligthAlpha; if (br != null && br.scheme == ColorScheme.dark) { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.black)); broadcastSpamControlBorder.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(darkSchemeTextColor); activity.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlText.setTextColor(lightSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(lightSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(lightSchemeTextColor), Color.green(lightSchemeTextColor), Color.blue(lightSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); alpha = darkAlpha; } else { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.white)); broadcastSpamControlBorder.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(lightSchemeTextColor); activity.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlText.setTextColor(darkSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(darkSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(darkSchemeTextColor), Color.green(darkSchemeTextColor), Color.blue(darkSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); } if (br != null && br.color != null) { int alphaColor = Color.argb(alpha, Color.red(br.color), Color.green(br.color), Color.blue(br.color)); broadcastSpamControl.setBackgroundColor(alphaColor); } mService.postOnUIHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { int maxHeight = broadcastSpamControl.getHeight(); broadcastSpamControlDivider.getLayoutParams().height = maxHeight; broadcastSpamControlDivider.requestLayout(); broadcastSpamControlSettingsContainer.getLayoutParams().height = maxHeight; broadcastSpamControlSettingsContainer.requestLayout(); broadcastSpamControlTextContainer.getLayoutParams().height = maxHeight; broadcastSpamControlTextContainer.requestLayout(); int broadcastSpamControlWidth = broadcastSpamControl.getWidth(); android.view.ViewGroup.LayoutParams lp = broadcastSpamControlSettingsContainer .getLayoutParams(); lp.width = broadcastSpamControlWidth / 4; broadcastSpamControlSettingsContainer.setLayoutParams(lp); } }); } if (!isUpdate) collapseDetails(DETAIL_SECTIONS); }
From source file:org.telegram.ui.ChannelCreateActivity.java
@Override public View createView(Context context) { searching = false;/*w w w .ja v a 2 s .com*/ searchWas = false; actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (currentStep == 0) { if (donePressed) { return; } if (nameTextView.length() == 0) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(nameTextView, 2, 0); return; } donePressed = true; if (avatarUpdater.uploadingAvatar != null) { createAfterUpload = true; progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { createAfterUpload = false; progressDialog = null; donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); return; } final int reqId = MessagesController.getInstance().createChat( nameTextView.getText().toString(), new ArrayList<Integer>(), descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL, ChannelCreateActivity.this); progressDialog = new ProgressDialog(getParentActivity()); progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ConnectionsManager.getInstance().cancelRequest(reqId, true); donePressed = false; try { dialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); progressDialog.show(); } else if (currentStep == 1) { if (!isPrivate) { if (nameTextView.length() == 0) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername", R.string.ChannelPublicEmptyUsername)); builder.setPositiveButton(LocaleController.getString("Close", R.string.Close), null); showDialog(builder.create()); return; } else { if (!lastNameAvailable) { Vibrator v = (Vibrator) getParentActivity() .getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(checkTextView, 2, 0); return; } else { MessagesController.getInstance().updateChannelUserName(chatId, lastCheckName); } } } Bundle args = new Bundle(); args.putInt("step", 2); args.putInt("chat_id", chatId); presentFragment(new ChannelCreateActivity(args), true); } else { ArrayList<TLRPC.InputUser> result = new ArrayList<>(); for (Integer uid : selectedContacts.keySet()) { TLRPC.InputUser user = MessagesController .getInputUser(MessagesController.getInstance().getUser(uid)); if (user != null) { result.add(user); } } MessagesController.getInstance().addUsersToChannel(chatId, result, null); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); Bundle args2 = new Bundle(); args2.putInt("chat_id", chatId); presentFragment(new ChatActivity(args2), true); } } } }); ActionBarMenu menu = actionBar.createMenu(); doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); if (currentStep != 2) { fragmentView = new ScrollView(context); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } else { fragmentView = new LinearLayout(context); fragmentView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); linearLayout = (LinearLayout) fragmentView; } linearLayout.setOrientation(LinearLayout.VERTICAL); if (currentStep == 0) { actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel)); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); FrameLayout frameLayout = new FrameLayout(context); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); avatarImage = new BackupImageView(context); avatarImage.setRoundRadius(AndroidUtilities.dp(32)); avatarDrawable.setInfo(5, null, null, false); avatarDrawable.setDrawPhoto(true); avatarImage.setImageDrawable(avatarDrawable); frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12)); avatarImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; if (avatar != null) { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("DeletePhoto", R.string.DeletePhoto) }; } else { items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley) }; } builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { avatarUpdater.openCamera(); } else if (i == 1) { avatarUpdater.openGallery(); } else if (i == 2) { avatar = null; uploadedAvatar = null; avatarImage.setImage(avatar, "50_50", avatarDrawable); } } }); showDialog(builder.create()); } }); nameTextView = new EditText(context); nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName)); if (nameToSet != null) { nameTextView.setText(nameToSet); nameToSet = null; } nameTextView.setMaxLines(4); nameTextView .setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); InputFilter[] inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(100); nameTextView.setFilters(inputFilters); nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8)); AndroidUtilities.clearCursorDrawable(nameTextView); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0, LocaleController.isRTL ? 96 : 16, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null, null, false); avatarImage.invalidate(); } }); descriptionTextView = new EditText(context); descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //descriptionTextView.setHintTextColor(0xff979797); descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6)); descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); inputFilters = new InputFilter[1]; inputFilters[0] = new InputFilter.LengthFilter(120); descriptionTextView.setFilters(inputFilters); descriptionTextView .setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder)); AndroidUtilities.clearCursorDrawable(descriptionTextView); linearLayout.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0)); descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) { doneButton.performClick(); return true; } return false; } }); descriptionTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { } }); TextView helpTextView = new TextView(context); helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); //helpTextView.setTextColor(0xff6d6d72); helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo)); linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20)); } else if (currentStep == 1) { actionBar.setTitle(LocaleController.getString("ChannelSettings", R.string.ChannelSettings)); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1 = new RadioButtonCell(context); radioButtonCell1.setElevation(0); radioButtonCell1.setForeground(R.drawable.list_selector); radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false); linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isPrivate) { return; } isPrivate = false; updatePrivatePublic(); } }); radioButtonCell2 = new RadioButtonCell(context); radioButtonCell2.setElevation(0); radioButtonCell2.setForeground(R.drawable.list_selector); radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate, false); linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isPrivate) { return; } isPrivate = true; updatePrivatePublic(); } }); sectionCell = new ShadowSectionCell(context); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); linkContainer = new LinearLayout(context); linkContainer.setOrientation(LinearLayout.VERTICAL); linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linkContainer.setElevation(AndroidUtilities.dp(2)); linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); linkContainer.addView(headerCell); publicContainer = new LinearLayout(context); publicContainer.setOrientation(LinearLayout.HORIZONTAL); linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0)); EditText editText = new EditText(context); editText.setText("telegram.me/"); editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //editText.setHintTextColor(0xff979797); editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); editText.setMaxLines(1); editText.setLines(1); editText.setEnabled(false); editText.setBackgroundDrawable(null); editText.setPadding(0, 0, 0, 0); editText.setSingleLine(true); editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); editText.setImeOptions(EditorInfo.IME_ACTION_DONE); publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setMaxLines(1); nameTextView.setLines(1); nameTextView.setBackgroundDrawable(null); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setSingleLine(true); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); nameTextView.setHint( LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder)); AndroidUtilities.clearCursorDrawable(nameTextView); publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { checkUserName(nameTextView.getText().toString()); } @Override public void afterTextChanged(Editable editable) { } }); privateContainer = new TextBlockCell(context); privateContainer.setForeground(R.drawable.list_selector); privateContainer.setElevation(0); linkContainer.addView(privateContainer); privateContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (invite == null) { return; } try { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link); clipboard.setPrimaryClip(clip); Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT) .show(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); checkTextView = new TextView(context); checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); checkTextView.setVisibility(View.GONE); linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7)); typeInfoCell = new TextInfoPrivacyCell(context); //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); loadingAdminedCell = new LoadingCell(context); linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminedInfoCell = new TextInfoPrivacyCell(context); //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); updatePrivatePublic(); } else if (currentStep == 2) { actionBar.setTitle(LocaleController.getString("ChannelAddMembers", R.string.ChannelAddMembers)); actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size())); searchListViewAdapter = new SearchAdapter(context, null, false, false, false, false); searchListViewAdapter.setCheckedMap(selectedContacts); searchListViewAdapter.setUseUserCell(true); listViewAdapter = new ContactsAdapter(context, 1, false, null, false); listViewAdapter.setCheckedMap(selectedContacts); FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.chat_list_background)); linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE); nameTextView.setMinimumHeight(AndroidUtilities.dp(54)); nameTextView.setSingleLine(false); nameTextView.setLines(2); nameTextView.setMaxLines(2); nameTextView.setVerticalScrollBarEnabled(true); nameTextView.setHorizontalScrollBarEnabled(false); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setHint(LocaleController.getString("AddMutual", R.string.AddMutual)); nameTextView.setTextIsSelectable(false); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI); nameTextView .setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); AndroidUtilities.clearCursorDrawable(nameTextView); frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 10, 0, 10, 0)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) { if (!ignoreChange) { beforeChangeIndex = nameTextView.getSelectionStart(); changeString = new SpannableString(charSequence); } } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { if (!ignoreChange) { boolean search = false; int afterChangeIndex = nameTextView.getSelectionEnd(); if (editable.toString().length() < changeString.toString().length()) { String deletedString = ""; try { deletedString = changeString.toString().substring(afterChangeIndex, beforeChangeIndex); } catch (Exception e) { FileLog.e("tmessages", e); } if (deletedString.length() > 0) { if (searching && searchWas) { search = true; } Spannable span = nameTextView.getText(); for (int a = 0; a < allSpans.size(); a++) { ChipSpan sp = allSpans.get(a); if (span.getSpanStart(sp) == -1) { allSpans.remove(sp); selectedContacts.remove(sp.uid); } } actionBar.setSubtitle( LocaleController.formatPluralString("Members", selectedContacts.size())); listView.invalidateViews(); } else { search = true; } } else { search = true; } if (search) { String text = nameTextView.getText().toString().replace("<", ""); if (text.length() != 0) { searching = true; searchWas = true; if (listView != null) { listView.setAdapter(searchListViewAdapter); searchListViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(false); listView.setFastScrollEnabled(false); listView.setVerticalScrollBarEnabled(true); } if (emptyTextView != null) { emptyTextView .setText(LocaleController.getString("NoResult", R.string.NoResult)); } searchListViewAdapter.searchDialogs(text); } else { searchListViewAdapter.searchDialogs(null); searching = false; searchWas = false; listView.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(true); listView.setFastScrollEnabled(true); listView.setVerticalScrollBarEnabled(false); emptyTextView .setText(LocaleController.getString("NoContacts", R.string.NoContacts)); } } } } }); LinearLayout emptyTextLayout = new LinearLayout(context); emptyTextLayout.setVisibility(View.INVISIBLE); emptyTextLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(emptyTextLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); emptyTextLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyTextView = new TextView(context); emptyTextView.setTextColor(0xff808080); emptyTextView.setTextSize(20); emptyTextView.setGravity(Gravity.CENTER); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); emptyTextLayout.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); FrameLayout frameLayout2 = new FrameLayout(context); emptyTextLayout.addView(frameLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0.5f)); listView = new LetterSectionsListView(context); listView.setEmptyView(emptyTextLayout); listView.setVerticalScrollBarEnabled(false); listView.setDivider(null); listView.setDividerHeight(0); listView.setFastScrollEnabled(true); listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); listView.setAdapter(listViewAdapter); listView.setFastScrollAlwaysVisible(true); listView.setVerticalScrollbarPosition( LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); linearLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { TLRPC.User user; if (searching && searchWas) { user = (TLRPC.User) searchListViewAdapter.getItem(i); } else { int section = listViewAdapter.getSectionForPosition(i); int row = listViewAdapter.getPositionInSectionForPosition(i); if (row < 0 || section < 0) { return; } user = (TLRPC.User) listViewAdapter.getItem(section, row); } if (user == null) { return; } boolean check = true; if (selectedContacts.containsKey(user.id)) { check = false; try { ChipSpan span = selectedContacts.get(user.id); selectedContacts.remove(user.id); SpannableStringBuilder text = new SpannableStringBuilder(nameTextView.getText()); text.delete(text.getSpanStart(span), text.getSpanEnd(span)); allSpans.remove(span); ignoreChange = true; nameTextView.setText(text); nameTextView.setSelection(text.length()); ignoreChange = false; } catch (Exception e) { FileLog.e("tmessages", e); } } else { ignoreChange = true; ChipSpan span = createAndPutChipForUser(user); if (span != null) { span.uid = user.id; } ignoreChange = false; if (span == null) { return; } } actionBar.setSubtitle(LocaleController.formatPluralString("Members", selectedContacts.size())); if (searching || searchWas) { ignoreChange = true; SpannableStringBuilder ssb = new SpannableStringBuilder(""); for (ImageSpan sp : allSpans) { ssb.append("<<"); ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); } nameTextView.setText(ssb); nameTextView.setSelection(ssb.length()); ignoreChange = false; searchListViewAdapter.searchDialogs(null); searching = false; searchWas = false; listView.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); listView.setFastScrollAlwaysVisible(true); listView.setFastScrollEnabled(true); listView.setVerticalScrollBarEnabled(false); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); } else { if (view instanceof UserCell) { ((UserCell) view).setChecked(check, true); } } } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i == SCROLL_STATE_TOUCH_SCROLL) { AndroidUtilities.hideKeyboard(nameTextView); } if (listViewAdapter != null) { listViewAdapter.setIsScrolling(i != SCROLL_STATE_IDLE); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (absListView.isFastScrollEnabled()) { AndroidUtilities.clearDrawableAnimation(absListView); } } }); } return fragmentView; }
From source file:cn.jasonlv.siri.activity.MainActivity.java
@Override public void onResults(Bundle results) { long end2finish = System.currentTimeMillis() - speechEndTime; status = STATUS_None;/*from w ww . jav a2 s.c o m*/ ArrayList<String> nbest = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); print("?" + Arrays.toString(nbest.toArray(new String[nbest.size()]))); String json_res = results.getString("origin_result"); Log.e(LOG_TAG, json_res); View inputPanel = getLayoutInflater().inflate(R.layout.input_layout, null); TextView inputTextView = (TextView) inputPanel.findViewById(R.id.input_text); inputTextView.setText(nbest.get(0)); inputPanel.setFocusable(true); inputPanel.setFocusableInTouchMode(true); container.addView(inputPanel); //View fragmentContainer = getLayoutInflater().inflate(R.layout.fragment_container_layout, null); //container.addView(fragmentContainer); FrameLayout fragmentContainer = new FrameLayout(this); fragmentContainer.setId(fragmentConatainerId); fragmentContainer.setFocusable(true); fragmentContainer.setFocusableInTouchMode(true); container.addView(fragmentContainer); onProcessingResult(nbest, json_res, fragmentConatainerId); fragmentConatainerId++; scrollView.post(new Runnable() { @Override public void run() { scrollView.fullScroll(View.FOCUS_DOWN); } }); }