@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(this)); Colors.updateColors(this); startService(new Intent(this, JTalkService.class)); service = JTalkService.getInstance(); prefs = PreferenceManager.getDefaultSharedPreferences(this); setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark); setContentView(R.layout.roster); LinearLayout roster = (LinearLayout) findViewById(R.id.roster_linear); roster.setBackgroundColor(Colors.BACKGROUND); getActionBar().setHomeButtonEnabled(true); statusArray = getResources().getStringArray(R.array.statusArray); rosterAdapter = new RosterAdapter(this); simpleAdapter = new NoGroupsAdapter(this); searchAdapter = new SearchAdapter(this); int cols = 1; if (!prefs.getBoolean("ShowGroups", true) && !prefs.getBoolean("ShowMucGroup", false)) { try { cols = Integer.parseInt(prefs.getString("RosterColumns", "1")); } catch (Exception e) { cols = 1; } } gridView = (GridView) findViewById(R.id.users); gridView.setNumColumns(cols); gridView.setCacheColorHint(0x00000000); gridView.setOnItemClickListener(this); gridView.setOnItemLongClickListener(this); gridView.setAdapter(rosterAdapter); if (getIntent().getBooleanExtra("status", false)) { RosterDialogs.changeStatusDialog(this, null, null); } if (getIntent().getBooleanExtra("password", false)) { String account = getIntent().getStringExtra("account"); RosterDialogs.passwordDialog(this, account); } if (getIntent().getBooleanExtra("subscribtion", false)) { String account = getIntent().getStringExtra("account"); String jid = getIntent().getStringExtra("jid"); RosterDialogs.subscribtionRequestDialog(this, account, jid); } File table = new File(Constants.PATH_SMILES + "/default/table.xml"); if (!table.exists()) { new CreateDefaultSmiles().execute(); } else { Cursor cursor = getContentResolver() .query( JTalkProvider.ACCOUNT_URI, null, AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null); if (cursor == null || cursor.getCount() < 1) startActivity(new Intent(this, Accounts.class)); } if (prefs.getBoolean("BUG", false)) { new ErrorDialog(this).show(); } String action = getIntent().getAction(); if (action != null && action.equals(Intent.ACTION_VIEW)) { Uri data = getIntent().getData(); if (data != null && data.getScheme().equals("xmpp")) { XMPPUri xmppUri; try { xmppUri = new XMPPUri(data); } catch (IllegalArgumentException e) { xmppUri = null; } List<String> accounts = new ArrayList<String>(); for (XMPPConnection connection : service.getAllConnections()) { accounts.add(StringUtils.parseBareAddress(connection.getUser())); } if (xmppUri != null && !accounts.isEmpty()) { final String xmppJid = xmppUri.getJid(); final String body = xmppUri.getBody(); String queryType = xmppUri.getQueryType(); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, accounts); if (queryType.equals("roster")) { RosterDialogs.addDialog(this, xmppUri.getJid()); } else if (queryType.equals("join")) { if (accounts.size() > 1) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.Accounts); builder.setAdapter( adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String account = adapter.getItem(which); MucDialogs.joinDialog(RosterActivity.this, account, xmppJid, null); } }); builder.create().show(); } else MucDialogs.joinDialog(RosterActivity.this, accounts.get(0), xmppJid, null); } else { service.setText(xmppJid, body); if (accounts.size() > 1) { service.setText(xmppJid, body); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.Accounts); builder.setAdapter( adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String account = adapter.getItem(which); Intent intent = new Intent(RosterActivity.this, Chat.class); intent.putExtra("account", account); intent.putExtra("jid", xmppJid); startActivity(intent); } }); builder.create().show(); } else { Intent intent = new Intent(RosterActivity.this, Chat.class); intent.putExtra("account", accounts.get(0)); intent.putExtra("jid", xmppJid); startActivity(intent); } } } } } }
@Override public View onCreateView( final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { peerType = savedInstanceState.getInt("peerType"); peerId = savedInstanceState.getInt("peerId"); } View res = inflater.inflate(R.layout.media_main, container, false); gridView = (GridView) res.findViewById(R.id.mediaGrid); loading = res.findViewById(R.id.loading); empty = res.findViewById(R.id.empty); gridView.setVisibility(View.GONE); empty.setVisibility(View.GONE); loading.setVisibility(View.GONE); mediaSource = application.getDataSourceKernel().getMediaSource(peerType, peerId); mediaSource.getSource().onConnected(); records = mediaSource.getSource().getCurrentWorkingSet(); // final List<MediaRecord> lazyList = // application.getEngine().getMediaEngine().lazyQueryMedia(peerType, peerId); gridView.setPadding(0, PreviewConfig.MEDIA_SPACING, 0, PreviewConfig.MEDIA_SPACING); gridView.setNumColumns(PreviewConfig.MEDIA_ROW_COUNT); gridView.setColumnWidth(PreviewConfig.MEDIA_PREVIEW); gridView.setVerticalSpacing(PreviewConfig.MEDIA_SPACING); gridView.setHorizontalSpacing(PreviewConfig.MEDIA_SPACING); gridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if (i >= 0 && i < records.size()) { getRootController().openImage(records.get(i).getMid(), peerType, peerId); } else { mediaSource.requestLoadMore(records.size()); } } }); final Context context = getActivity(); adapter = new BaseAdapter() { @Override public int getCount() { if (isLoading) { return records.size() + 1; } else { return records.size(); } } @Override public MediaRecord getItem(int i) { if (i >= 0 && i < records.size()) { return records.get(i); } else { return null; } } @Override public long getItemId(int i) { if (i >= 0 && i < records.size()) { return records.get(i).getDatabaseId(); } else { return 0; } } @Override public boolean hasStableIds() { return true; } @Override public int getItemViewType(int i) { if (i >= 0 && i < records.size()) { return 0; } else { return 1; } } @Override public int getViewTypeCount() { return 2; } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int i) { return i >= 0 && i < records.size() || isLoadingError; } @Override public View getView(int i, View view, ViewGroup viewGroup) { if (i >= 0 && i < records.size()) { mediaSource.getSource().onItemsShown(i); MediaRecord record = getItem(i); if (view == null) { view = newView(context, record, viewGroup); } bindView(view, context, record, i); return view; } else { if (view == null) { view = inflater.inflate(R.layout.media_loading, viewGroup, false); GridView.LayoutParams imageParams = new GridView.LayoutParams( PreviewConfig.MEDIA_PREVIEW, PreviewConfig.MEDIA_PREVIEW); view.setLayoutParams(imageParams); } if (isLoadingError) { view.findViewById(R.id.progress).setVisibility(View.GONE); view.findViewById(R.id.retry).setVisibility(View.VISIBLE); } else { view.findViewById(R.id.progress).setVisibility(View.VISIBLE); view.findViewById(R.id.retry).setVisibility(View.GONE); } return view; } } public View newView(Context context, MediaRecord object, ViewGroup parent) { GridView.LayoutParams layoutParams = new GridView.LayoutParams(PreviewConfig.MEDIA_PREVIEW, PreviewConfig.MEDIA_PREVIEW); FrameLayout frameLayout = new FrameLayout(context); frameLayout.setLayoutParams(layoutParams); SmallPreviewView smallPreviewView = new SmallPreviewView(context); FrameLayout.LayoutParams imageParams = new FrameLayout.LayoutParams( PreviewConfig.MEDIA_PREVIEW, PreviewConfig.MEDIA_PREVIEW); smallPreviewView.setLayoutParams(imageParams); ImageView videoLogo = new ImageView(context); videoLogo.setImageResource(R.drawable.st_media_ic_play); FrameLayout.LayoutParams timeParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); timeParams.gravity = Gravity.CENTER; videoLogo.setLayoutParams(timeParams); frameLayout.addView(smallPreviewView); frameLayout.addView(videoLogo); return frameLayout; } public void bindView(View view, Context context, MediaRecord object, int index) { SmallPreviewView imageView = (SmallPreviewView) ((ViewGroup) view).getChildAt(0); View videoView = ((ViewGroup) view).getChildAt(1); if (object.getPreview() instanceof TLLocalVideo) { videoView.setVisibility(View.VISIBLE); } else { videoView.setVisibility(View.INVISIBLE); } if (object.getPreview() instanceof TLLocalPhoto) { TLLocalPhoto localPhoto = (TLLocalPhoto) object.getPreview(); String key = DownloadManager.getPhotoKey(localPhoto); if (application.getDownloadManager().getState(key) == DownloadState.COMPLETED) { imageView.requestFile(application.getDownloadManager().getFileName(key)); } else { if (localPhoto.getFastPreviewW() != 0 && localPhoto.getFastPreviewH() != 0) { imageView.requestFast(localPhoto); } else { imageView.clearImage(); } } } else if (object.getPreview() instanceof TLLocalVideo) { TLLocalVideo localVideo = (TLLocalVideo) object.getPreview(); if (localVideo.getFastPreview().length > 0) { imageView.requestFast(localVideo); } else { imageView.clearImage(); } } else if (object.getPreview() instanceof TLLocalDocument) { TLLocalDocument localVideo = (TLLocalDocument) object.getPreview(); if (localVideo.getFastPreview().length > 0) { imageView.requestFast(localVideo); } else { imageView.clearImage(); } } else { imageView.clearImage(); } } }; gridView.setAdapter(adapter); return res; }