List of usage examples for android.view Display getWidth
@Deprecated public int getWidth()
From source file:io.selendroid.server.model.DefaultSelendroidDriver.java
@Override @SuppressWarnings("deprecation") public byte[] takeScreenshot() { ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance(); // TODO ddary review later, but with getRecentDecorView() it seems to work better // long drawingTime = 0; // View container = null; // for (View view : viewAnalyzer.getTopLevelViews()) { // if (view != null && view.isShown() && view.hasWindowFocus() // && view.getDrawingTime() > drawingTime) { // container = view; // drawingTime = view.getDrawingTime(); // }// w w w. j a v a 2 s . c o m // } // final View mainView = container; final View mainView = viewAnalyzer.getRecentDecorView(); if (mainView == null) { throw new SelendroidException("No open windows."); } done = false; long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis(); final byte[][] rawPng = new byte[1][1]; ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { Display display = serverInstrumentation.getCurrentActivity().getWindowManager() .getDefaultDisplay(); Point size = new Point(); try { display.getSize(size); } catch (NoSuchMethodError ignore) { // Older than api level 13 size.x = display.getWidth(); size.y = display.getHeight(); } // Get root view View view = mainView.getRootView(); // Create the bitmap to use to draw the screenshot final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); // Get current theme to know which background to use final Activity activity = serverInstrumentation.getCurrentActivity(); final Theme theme = activity.getTheme(); final TypedArray ta = theme .obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); final int res = ta.getResourceId(0, 0); final Drawable background = activity.getResources().getDrawable(res); // Draw background background.draw(canvas); // Draw views view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (!bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream)) { throw new RuntimeException("Error while compressing screenshot image."); } try { stream.flush(); stream.close(); } catch (IOException e) { throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage()); } finally { Closeable closeable = (Closeable) stream; try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { // ignore } } rawPng[0] = stream.toByteArray(); mainView.destroyDrawingCache(); done = true; syncObject.notify(); } } }); waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot."); return rawPng[0]; }
From source file:com.tealeaf.TeaLeaf.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PluginManager.init(this); instance = this; setFullscreenFlag();//from w w w .ja va 2 s . c o m configureActivity(); String appID = findAppID(); options = new TeaLeafOptions(this); PluginManager.callAll("onCreate", this, savedInstanceState); //check intent for test app info Bundle bundle = getIntent().getExtras(); boolean isTestApp = false; if (bundle != null) { isTestApp = bundle.getBoolean("isTestApp", false); if (isTestApp) { options.setAppID(appID); boolean isPortrait = bundle.getBoolean("isPortrait", false); if (isPortrait) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } options.setCodeHost(bundle.getString("hostValue")); options.setCodePort(bundle.getInt("portValue")); String simulateID = bundle.getString("simulateID"); options.setSimulateID(simulateID); } } getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); group = new FrameLayout(this); setContentView(group); // TextEditViewHandler setup textEditView = new TextEditViewHandler(this); settings = new Settings(this); remoteLogger = (ILogger) getLoggerInstance(this); checkUpdate(); compareVersions(); setLaunchUri(); // defer building all of these things until we have the absolutely correct options logger.buildLogger(this, remoteLogger); resourceManager = new ResourceManager(this, options); contactList = new ContactList(this, resourceManager); soundQueue = new SoundQueue(this, resourceManager); localStorage = new LocalStorage(this, options); // start push notifications, but defer for 10 seconds to give us time to start up PushBroadcastReceiver.scheduleNext(this, 10); glView = new TeaLeafGLSurfaceView(this); glViewPaused = false; // default screen dimensions Display display = getWindow().getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); int orientation = getRequestedOrientation(); // gets real screen dimensions without nav bars on recent API versions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Point screenSize = new Point(); try { display.getRealSize(screenSize); width = screenSize.x; height = screenSize.y; } catch (NoSuchMethodError e) { } } // flip width and height based on orientation if ((orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && height > width) || (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && width > height)) { int tempWidth = width; width = height; height = tempWidth; } final AbsoluteLayout absLayout = new AbsoluteLayout(this); absLayout.setLayoutParams(new android.view.ViewGroup.LayoutParams(width, height)); absLayout.addView(glView, new android.view.ViewGroup.LayoutParams(width, height)); group.addView(absLayout); editText = EditTextView.Init(this); if (isTestApp) { startGame(); } soundQueue.playSound(SoundQueue.LOADING_SOUND); doFirstRun(); remoteLogger.sendLaunchEvent(this); paused = false; menuButtonHandler = MenuButtonHandlerFactory.getButtonHandler(this); group.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { // get visible area of the view Rect r = new Rect(); group.getWindowVisibleDisplayFrame(r); int visibleHeight = r.bottom; // TODO // maybe this should be renamed if (visibleHeight != lastVisibleHeight) { lastVisibleHeight = visibleHeight; EventQueue.pushEvent(new KeyboardScreenResizeEvent(visibleHeight)); } } }); }
From source file:tw.com.sti.store.api.android.AndroidApiService.java
private AndroidApiService(Context context, Configuration config) { this.config = config; this.apiUrl = new ApiUrl(config); if (Logger.DEBUG) L.d("new ApiService()"); sdkVer = Build.VERSION.SDK;/*from w w w . j a v a 2 s . co m*/ sdkRel = Build.VERSION.RELEASE; try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); storeId = pi.packageName; clientVer = "" + pi.versionCode; } catch (NameNotFoundException e) { } TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = tm.getDeviceId() == null ? "0" : tm.getDeviceId(); macAddress = NetworkUtils.getDeviceMacAddress(context); subscriberId = tm.getSubscriberId() == null ? "0" : tm.getSubscriberId(); simSerialNumber = tm.getSimSerialNumber() == null ? "0" : tm.getSimSerialNumber(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); try { Class<Display> cls = Display.class; Method method = cls.getMethod("getRotation"); Object retobj = method.invoke(display); int rotation = Integer.parseInt(retobj.toString()); if (Surface.ROTATION_0 == rotation || Surface.ROTATION_180 == rotation) { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } else { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } } catch (Exception e) { if (display.getOrientation() == 1) { wpx = "" + display.getHeight(); hpx = "" + display.getWidth(); } else { wpx = "" + display.getWidth(); hpx = "" + display.getHeight(); } } SharedPreferences pref = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); // token = pref.getString(PREF_KEY_TOKEN, ""); // uid = pref.getString(PREF_KEY_UID, ""); // userId = pref.getString(PREF_KEY_USER_ID, ""); appFilter = pref.getInt(PREF_KEY_APP_FILTER, 0); // ipLoginEnable = pref.getBoolean(PREF_KEY_IP_LOGIN_ENABLE, true); // ??SIM? String pref_subscriberId = pref.getString(PREF_KEY_SUBSCRIBER_ID, "0"); String pref_simSerialNumber = pref.getString(PREF_KEY_SIM_SERIAL_NUMBER, "0"); if (!subscriberId.equals(pref_subscriberId) || !simSerialNumber.equals(pref_simSerialNumber)) { if (Logger.DEBUG) L.d("Change SIM card."); cleanCredential(context); } this.getCredential(context); }
From source file:paulscode.android.mupen64plusae.persistent.UserPrefs.java
/** * Instantiates a new user preferences wrapper. * /*ww w. j a va 2 s .c o m*/ * @param context The application context. */ @SuppressWarnings("deprecation") @SuppressLint("InlinedApi") @TargetApi(17) public UserPrefs(Context context) { AppData appData = new AppData(context); mPreferences = PreferenceManager.getDefaultSharedPreferences(context); // Locale mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE); mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode); Locale[] availableLocales = Locale.getAvailableLocales(); String[] values = context.getResources().getStringArray(R.array.localeOverride_values); String[] entries = new String[values.length]; for (int i = values.length - 1; i > 0; i--) { Locale locale = createLocale(values[i]); // Get intersection of languages (available on device) and (translated for Mupen) if (ArrayUtils.contains(availableLocales, locale)) { // Get the name of the language, as written natively entries[i] = WordUtils.capitalize(locale.getDisplayName(locale)); } else { // Remove the item from the list entries = (String[]) ArrayUtils.remove(entries, i); values = (String[]) ArrayUtils.remove(values, i); } } entries[0] = context.getString(R.string.localeOverride_entrySystemDefault); mLocaleNames = entries; mLocaleCodes = values; // Files userDataDir = mPreferences.getString("pathGameSaves", ""); galleryDataDir = userDataDir + "/GalleryData"; profilesDir = userDataDir + "/Profiles"; crashLogDir = userDataDir + "/CrashLogs"; coreUserDataDir = userDataDir + "/CoreConfig/UserData"; coreUserCacheDir = userDataDir + "/CoreConfig/UserCache"; hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively romInfoCache_cfg = galleryDataDir + "/romInfoCache.cfg"; controllerProfiles_cfg = profilesDir + "/controller.cfg"; touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg"; emulationProfiles_cfg = profilesDir + "/emulation.cfg"; customCheats_txt = profilesDir + "/customCheats.txt"; // Plug-ins audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin"); // Touchscreen prefs isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false); touchscreenRefresh = getSafeInt(mPreferences, "touchscreenRefresh", 0); touchscreenScale = ((float) mPreferences.getInt("touchscreenScale", 100)) / 100.0f; touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100; touchscreenSkin = appData.touchscreenSkinsDir + "/" + mPreferences.getString("touchscreenStyle", "Outline"); touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0); // Xperia PLAY touchpad prefs isTouchpadEnabled = appData.hardwareInfo.isXperiaPlay && mPreferences.getBoolean("touchpadEnabled", true); isTouchpadFeedbackEnabled = mPreferences.getBoolean("touchpadFeedback", false); touchpadSkin = appData.touchpadSkinsDir + "/Xperia-Play"; ConfigFile touchpad_cfg = new ConfigFile(appData.touchpadProfiles_cfg); ConfigSection section = touchpad_cfg.get(mPreferences.getString("touchpadLayout", "")); if (section != null) touchpadProfile = new Profile(true, section); else touchpadProfile = null; // Video prefs displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0); displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL); int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50); displayActionBarTransparency = (255 * transparencyPercent) / 100; displayFpsRefresh = getSafeInt(mPreferences, "displayFpsRefresh", 0); isFpsEnabled = displayFpsRefresh > 0; videoHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1); videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-0.2"), -0.2f); isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false); // Audio prefs audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false); audioSecondaryBufferSize = getSafeInt(mPreferences, "audioBufferSize", 2048); if (audioPlugin.enabled) isFramelimiterEnabled = mPreferences.getBoolean("audioSynchronize", true); else isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit"); // User interface modes String navMode = mPreferences.getString("navigationMode", "auto"); if (navMode.equals("bigscreen")) isBigScreenMode = true; else if (navMode.equals("standard")) isBigScreenMode = false; else isBigScreenMode = AppData.IS_OUYA_HARDWARE; // TODO: Add other systems as they enter market isActionBarAvailable = AppData.IS_HONEYCOMB && !isBigScreenMode; // Peripheral share mode isControllerShared = mPreferences.getBoolean("inputShareController", false); // Determine the key codes that should not be mapped to controls boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false); List<Integer> unmappables = new ArrayList<Integer>(); unmappables.add(KeyEvent.KEYCODE_MENU); if (AppData.IS_HONEYCOMB) { // Back key is needed to show/hide the action bar in HC+ unmappables.add(KeyEvent.KEYCODE_BACK); } if (!volKeysMappable) { unmappables.add(KeyEvent.KEYCODE_VOLUME_UP); unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN); unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE); } unmappableKeyCodes = Collections.unmodifiableList(unmappables); // Determine the pixel dimensions of the rendering context and view surface { // Screen size final WindowManager windowManager = (WindowManager) context .getSystemService(android.content.Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); int stretchWidth; int stretchHeight; if (display == null) { stretchWidth = stretchHeight = 0; } else if (AppData.IS_KITKAT && isImmersiveModeEnabled) { DisplayMetrics metrics = new DisplayMetrics(); display.getRealMetrics(metrics); stretchWidth = metrics.widthPixels; stretchHeight = metrics.heightPixels; } else { stretchWidth = display.getWidth(); stretchHeight = display.getHeight(); } float aspect = 0.75f; // TODO: Handle PAL boolean isLetterboxed = ((float) stretchHeight / (float) stretchWidth) > aspect; int zoomWidth = isLetterboxed ? stretchWidth : Math.round((float) stretchHeight / aspect); int zoomHeight = isLetterboxed ? Math.round((float) stretchWidth * aspect) : stretchHeight; int cropWidth = isLetterboxed ? Math.round((float) stretchHeight / aspect) : stretchWidth; int cropHeight = isLetterboxed ? stretchHeight : Math.round((float) stretchWidth * aspect); int hResolution = getSafeInt(mPreferences, "displayResolution", 0); String scaling = mPreferences.getString("displayScaling", "zoom"); if (hResolution == 0) { // Native resolution if (scaling.equals("stretch")) { videoRenderWidth = videoSurfaceWidth = stretchWidth; videoRenderHeight = videoSurfaceHeight = stretchHeight; } else if (scaling.equals("crop")) { videoRenderWidth = videoSurfaceWidth = cropWidth; videoRenderHeight = videoSurfaceHeight = cropHeight; } else // scaling.equals( "zoom") || scaling.equals( "none" ) { videoRenderWidth = videoSurfaceWidth = zoomWidth; videoRenderHeight = videoSurfaceHeight = zoomHeight; } } else { // Non-native resolution switch (hResolution) { case 720: videoRenderWidth = 960; videoRenderHeight = 720; break; case 600: videoRenderWidth = 800; videoRenderHeight = 600; break; case 480: videoRenderWidth = 640; videoRenderHeight = 480; break; case 360: videoRenderWidth = 480; videoRenderHeight = 360; break; case 240: videoRenderWidth = 320; videoRenderHeight = 240; break; case 120: videoRenderWidth = 160; videoRenderHeight = 120; break; default: videoRenderWidth = Math.round((float) hResolution / aspect); videoRenderHeight = hResolution; break; } if (scaling.equals("zoom")) { videoSurfaceWidth = zoomWidth; videoSurfaceHeight = zoomHeight; } else if (scaling.equals("crop")) { videoSurfaceWidth = cropWidth; videoSurfaceHeight = cropHeight; } else if (scaling.equals("stretch")) { videoSurfaceWidth = stretchWidth; videoSurfaceHeight = stretchHeight; } else // scaling.equals( "none" ) { videoSurfaceWidth = videoRenderWidth; videoSurfaceHeight = videoRenderHeight; } } } }
From source file:edu.pitt.gis.uniapp.UniApp.java
/** * Shows the splash screen over the full Activity *//* w w w . j a v a 2 s. c o m*/ @SuppressWarnings("deprecation") protected void showSplashScreen(final int time) { final UniApp that = this; Runnable runnable = new Runnable() { public void run() { // Get reference to display Display display = getWindowManager().getDefaultDisplay(); // Create the layout for the dialog LinearLayout root = new LinearLayout(that.getActivity()); root.setMinimumHeight(display.getHeight()); root.setMinimumWidth(display.getWidth()); root.setOrientation(LinearLayout.VERTICAL); root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK)); root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F)); root.setBackgroundResource(that.splashscreen); // Create and show the dialog splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar); // check to see if the splash screen should be full screen if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN) { splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } splashDialog.setContentView(root); splashDialog.setCancelable(false); splashDialog.show(); // Set Runnable to remove splash screen just in case final Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { removeSplashScreen(); } }, time); } }; this.runOnUiThread(runnable); }
From source file:org.telegram.ui.GalleryImageViewer.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a va 2s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Display display = getWindowManager().getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT < 13) { displaySize.set(display.getWidth(), display.getHeight()); } else { display.getSize(displaySize); } classGuid = ConnectionsManager.Instance.generateClassGuid(); setContentView(R.layout.gallery_layout); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setTitle(getString(R.string.Gallery)); actionBar.show(); mViewPager = (GalleryViewPager) findViewById(R.id.gallery_view_pager); ImageView shareButton = (ImageView) findViewById(R.id.gallery_view_share_button); ImageView deleteButton = (ImageView) findViewById(R.id.gallery_view_delete_button); nameTextView = (TextView) findViewById(R.id.gallery_view_name_text); timeTextView = (TextView) findViewById(R.id.gallery_view_time_text); bottomView = findViewById(R.id.gallery_view_bottom_view); fakeTitleView = (TextView) findViewById(R.id.fake_title_view); loadingProgress = (ProgressBar) findViewById(R.id.action_progress); title = (TextView) findViewById(R.id.action_bar_title); if (title == null) { final int titleId = getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) findViewById(titleId); } NotificationCenter.Instance.addObserver(this, FileLoader.FileDidFailedLoad); NotificationCenter.Instance.addObserver(this, FileLoader.FileDidLoaded); NotificationCenter.Instance.addObserver(this, FileLoader.FileLoadProgressChanged); NotificationCenter.Instance.addObserver(this, MessagesController.mediaCountDidLoaded); NotificationCenter.Instance.addObserver(this, MessagesController.mediaDidLoaded); NotificationCenter.Instance.addObserver(this, MessagesController.userPhotosLoaded); NotificationCenter.Instance.addObserver(this, 658); Integer index = null; if (localPagerAdapter == null) { final MessageObject file = (MessageObject) NotificationCenter.Instance.getFromMemCache(51); final TLRPC.FileLocation fileLocation = (TLRPC.FileLocation) NotificationCenter.Instance .getFromMemCache(53); final ArrayList<MessageObject> messagesArr = (ArrayList<MessageObject>) NotificationCenter.Instance .getFromMemCache(54); index = (Integer) NotificationCenter.Instance.getFromMemCache(55); Integer uid = (Integer) NotificationCenter.Instance.getFromMemCache(56); if (uid != null) { user_id = uid; } if (file != null) { ArrayList<MessageObject> imagesArr = new ArrayList<MessageObject>(); HashMap<Integer, MessageObject> imagesByIds = new HashMap<Integer, MessageObject>(); imagesArr.add(file); if (file.messageOwner.action == null || file.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) { needSearchMessage = true; imagesByIds.put(file.messageOwner.id, file); if (file.messageOwner.dialog_id != 0) { currentDialog = file.messageOwner.dialog_id; } else { if (file.messageOwner.to_id.chat_id != 0) { currentDialog = -file.messageOwner.to_id.chat_id; } else { if (file.messageOwner.to_id.user_id == UserConfig.clientUserId) { currentDialog = file.messageOwner.from_id; } else { currentDialog = file.messageOwner.to_id.user_id; } } } } localPagerAdapter = new LocalPagerAdapter(imagesArr, imagesByIds); } else if (fileLocation != null) { ArrayList<TLRPC.FileLocation> arr = new ArrayList<TLRPC.FileLocation>(); arr.add(fileLocation); withoutBottom = true; deleteButton.setVisibility(View.INVISIBLE); nameTextView.setVisibility(View.INVISIBLE); timeTextView.setVisibility(View.INVISIBLE); localPagerAdapter = new LocalPagerAdapter(arr); } else if (messagesArr != null) { ArrayList<MessageObject> imagesArr = new ArrayList<MessageObject>(); HashMap<Integer, MessageObject> imagesByIds = new HashMap<Integer, MessageObject>(); imagesArr.addAll(messagesArr); Collections.reverse(imagesArr); for (MessageObject message : imagesArr) { imagesByIds.put(message.messageOwner.id, message); } index = imagesArr.size() - index - 1; MessageObject object = imagesArr.get(0); if (object.messageOwner.dialog_id != 0) { currentDialog = object.messageOwner.dialog_id; } else { if (object.messageOwner.to_id.chat_id != 0) { currentDialog = -object.messageOwner.to_id.chat_id; } else { if (object.messageOwner.to_id.user_id == UserConfig.clientUserId) { currentDialog = object.messageOwner.from_id; } else { currentDialog = object.messageOwner.to_id.user_id; } } } localPagerAdapter = new LocalPagerAdapter(imagesArr, imagesByIds); } } mViewPager.setPageMargin(Utilities.dp(20)); mViewPager.setOffscreenPageLimit(1); mViewPager.setAdapter(localPagerAdapter); if (index != null) { fromAll = true; mViewPager.setCurrentItem(index); } shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { TLRPC.FileLocation file = getCurrentFile(); File f = new File(Utilities.getCacheDir(), file.volume_id + "_" + file.local_id + ".jpg"); if (f.exists()) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f)); startActivity(intent); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mViewPager == null || localPagerAdapter == null || localPagerAdapter.imagesArr == null) { return; } int item = mViewPager.getCurrentItem(); MessageObject obj = localPagerAdapter.imagesArr.get(item); if (obj.messageOwner.send_state == MessagesController.MESSAGE_SEND_STATE_SENT) { ArrayList<Integer> arr = new ArrayList<Integer>(); arr.add(obj.messageOwner.id); MessagesController.Instance.deleteMessages(arr); finish(); } } }); if (currentDialog != 0 && totalCount == 0) { MessagesController.Instance.getMediaCount(currentDialog, classGuid, true); } if (user_id != 0) { MessagesController.Instance.loadUserPhotos(user_id, 0, 30, 0, true, classGuid); } checkCurrentFile(); }
From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java
/** * Called when the activity is first created. *//*from w ww.j a v a 2s . c o m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.download); WindowManager w = getWindowManager(); Display d = w.getDefaultDisplay(); swipeDistance = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; swipeVelocity = (d.getWidth() + d.getHeight()) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100; gestureScanner = new GestureDetector(this); playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper); emptyTextView = (TextView) findViewById(R.id.download_empty); songTitleTextView = (TextView) findViewById(R.id.download_song_title); artistTextView = (TextView) findViewById(R.id.download_artist); albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image); positionTextView = (TextView) findViewById(R.id.download_position); durationTextView = (TextView) findViewById(R.id.download_duration); statusTextView = (TextView) findViewById(R.id.download_status); progressBar = (SeekBar) findViewById(R.id.download_progress_bar); playlistView = (ListView) findViewById(R.id.download_list); previousButton = findViewById(R.id.download_previous); nextButton = findViewById(R.id.download_next); pauseButton = findViewById(R.id.download_pause); stopButton = findViewById(R.id.download_stop); startButton = findViewById(R.id.download_start); shuffleButton = findViewById(R.id.download_shuffle); repeatButton = (ImageButton) findViewById(R.id.download_repeat); equalizerButton = (Button) findViewById(R.id.download_equalizer); visualizerButton = (Button) findViewById(R.id.download_visualizer); // jukeboxButton = (Button) findViewById(R.id.download_jukebox); // shareButton = (ImageView) findViewById(R.id.download_share); // starButton = (ImageView) findViewById(R.id.download_star); LinearLayout visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout); toggleListButton = (ImageButton) findViewById(R.id.download_toggle_list); View.OnTouchListener touchListener = new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent me) { return gestureScanner.onTouchEvent(me); } }; previousButton.setOnTouchListener(touchListener); nextButton.setOnTouchListener(touchListener); pauseButton.setOnTouchListener(touchListener); stopButton.setOnTouchListener(touchListener); // startButton.setOnTouchListener(touchListener); equalizerButton.setOnTouchListener(touchListener); visualizerButton.setOnTouchListener(touchListener); //jukeboxButton.setOnTouchListener(touchListener); //shareButton.setOnTouchListener(touchListener); //starButton.setOnTouchListener(touchListener); emptyTextView.setOnTouchListener(touchListener); albumArtImageView.setOnTouchListener(touchListener); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfNetworkOrStorageUnavailable(); getDownloadService().previous(); onCurrentChanged(); onProgressChanged(); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfNetworkOrStorageUnavailable(); if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) { getDownloadService().next(); onCurrentChanged(); onProgressChanged(); } } }); pauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getDownloadService().pause(); onCurrentChanged(); onProgressChanged(); } }); stopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getDownloadService().reset(); onCurrentChanged(); onProgressChanged(); } }); startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { warnIfNetworkOrStorageUnavailable(); start(); onCurrentChanged(); onProgressChanged(); } }); shuffleButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { getDownloadService().shuffle(); Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification); setControlsVisible(true); } }); repeatButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { RepeatMode repeatMode = getDownloadService().getRepeatMode().next(); getDownloadService().setRepeatMode(repeatMode); onDownloadListChanged(); switch (repeatMode) { case OFF: Util.toast(DownloadActivity.this, R.string.download_repeat_off); break; case ALL: Util.toast(DownloadActivity.this, R.string.download_repeat_all); break; case SINGLE: Util.toast(DownloadActivity.this, R.string.download_repeat_single); break; default: break; } setControlsVisible(true); } }); equalizerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(DownloadActivity.this, EqualizerActivity.class)); setControlsVisible(true); } }); visualizerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean active = !visualizerView.isActive(); visualizerView.setActive(active); getDownloadService().setShowVisualization(visualizerView.isActive()); updateButtons(); Util.toast(DownloadActivity.this, active ? R.string.download_visualizer_on : R.string.download_visualizer_off); setControlsVisible(true); } }); /* jukeboxButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean jukeboxEnabled = !getDownloadService().isJukeboxEnabled(); getDownloadService().setJukeboxEnabled(jukeboxEnabled); updateButtons(); Util.toast(DownloadActivity.this, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false); setControlsVisible(true); } });*/ /*shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentPlaying != null) { ShareUtil.shareInBackground(DownloadActivity.this, currentPlaying.getSong()); } setControlsVisible(true); } });*/ /*starButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentPlaying != null) { MusicDirectory.Entry song = currentPlaying.getSong(); StarUtil.starInBackground(DownloadActivity.this, song, !song.isStarred()); starButton.setImageResource(song.isStarred() ? R.drawable.starred : R.drawable.unstarred); } setControlsVisible(true); } });*/ toggleListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { toggleFullscreenAlbumArt(); } }); progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int position, boolean fromUser) { if (fromUser) { Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true); setControlsVisible(true); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { // Notification that the user has started a touch gesture. Clients may want to use this to disable advancing the seekbar. seekInProgress = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { // Notification that the user has finished a touch gesture. Clients may want to use this to re-enable advancing the seekbar. seekInProgress = false; int position = seekBar.getProgress(); Util.toast(DownloadActivity.this, Util.formatDuration(position / 1000), true); getDownloadService().seekTo(position); } }); playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { warnIfNetworkOrStorageUnavailable(); getDownloadService().play(position); onCurrentChanged(); onProgressChanged(); } }); registerForContextMenu(playlistView); DownloadService downloadService = getDownloadService(); if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) { warnIfNetworkOrStorageUnavailable(); downloadService.setShufflePlayEnabled(true); } boolean visualizerAvailable = downloadService != null && downloadService.getVisualizerController() != null; boolean equalizerAvailable = downloadService != null && downloadService.getEqualizerController() != null; if (!equalizerAvailable) { equalizerButton.setVisibility(View.GONE); } if (!visualizerAvailable) { visualizerButton.setVisibility(View.GONE); } else { visualizerView = new VisualizerView(this); visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); } final View overflowButton = findViewById(R.id.download_overflow); overflowButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new PopupMenuHelper().showMenu(DownloadActivity.this, overflowButton, R.menu.nowplaying); } }); }
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
private void initLayout() { /* get size of screen */ Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();// w ww . j a va 2 s . c o m FrameLayout.LayoutParams layoutParam = null; LayoutInflater myInflate = null; myInflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); FrameLayout topLayout = new FrameLayout(this); setContentView(topLayout); // openGLview mGLView = overlay.getGLView(); /* add camera view */ // int display_width_d = (int) (1.0 * bg_screen_width * screenWidth / // bg_width); // int display_height_d = (int) (1.0 * bg_screen_height * screenHeight / // bg_height); // int prev_rw, prev_rh; // if (1.0 * display_width_d / display_height_d > 1.0 * live_width / // live_height) { // prev_rh = display_height_d; // prev_rw = (int) (1.0 * display_height_d * live_width / live_height); // } else { // prev_rw = display_width_d; // prev_rh = (int) (1.0 * display_width_d * live_height / live_width); // } // layoutParam = new RelativeLayout.LayoutParams(prev_rw, prev_rh); // layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / // bg_height); // layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / // bg_width); int display_width_d = (int) (1.0 * screenWidth); int display_height_d = (int) (1.0 * screenHeight); int button_width = 0; int button_height = 0; int prev_rw, prev_rh; if (1.0 * display_width_d / display_height_d > 1.0 * live_width / live_height) { prev_rh = display_height_d; button_height = display_height_d; prev_rw = (int) (1.0 * display_height_d * live_width / live_height); button_width = display_width_d - prev_rw; } else { prev_rw = display_width_d; prev_rh = (int) (1.0 * display_width_d * live_height / live_width); } layoutParam = new FrameLayout.LayoutParams(prev_rw, prev_rh, Gravity.CENTER); //layoutParam = new FrameLayout.LayoutParams(prev_rw / 2, prev_rh / 2, Gravity.BOTTOM | Gravity.CENTER_VERTICAL); // layoutParam.topMargin = (int) (1.0 * bg_screen_by * screenHeight / // bg_height); // layoutParam.leftMargin = (int) (1.0 * bg_screen_bx * screenWidth / // bg_width); Log.d("LAYOUT", "display_width_d:" + display_width_d + ":: display_height_d:" + display_height_d + ":: prev_rw:" + prev_rw + ":: prev_rh:" + prev_rh + ":: live_width:" + live_width + ":: live_height:" + live_height + ":: button_width:" + button_width + ":: button_height:" + button_height); cameraDevice = openCamera(); cameraView = new CameraView(this, cameraDevice); topLayout.addView(cameraView, layoutParam); topLayout.addView(mGLView, layoutParam); FrameLayout preViewLayout = (FrameLayout) myInflate.inflate(R.layout.activity_streaming, null); layoutParam = new FrameLayout.LayoutParams(screenWidth, screenHeight); topLayout.addView(preViewLayout, layoutParam); Log.i(LOG_TAG, "cameara preview start: OK"); final Button recorderButton = (Button) findViewById(R.id.recorder_control); recorderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!recording) { Log.d(TAG, "attemptHandshaking"); attemptHandshake(); Log.w(LOG_TAG, "Start Button Pushed"); recorderButton.setText("Stop"); } else { stopRecording(); Log.w(LOG_TAG, "Stop Button Pushed"); recorderButton.setText("Start"); } } }); }
From source file:com.scoreflex.Scoreflex.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private static Point getScreenSize() { final Point size = new Point(); WindowManager w = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); Display d = w.getDefaultDisplay(); try {/*from w w w . j a v a 2 s. co m*/ Method getSizeMethod = d.getClass().getDeclaredMethod("getSize", Point.class); getSizeMethod.invoke(d, size); } catch (Exception e) { size.x = d.getWidth(); size.y = d.getHeight(); } return size; }
From source file:org.cryptsecure.Utility.java
/** * Get the screen width.// w ww . ja v a 2s. co m * * @param context * the context * @return the screen width */ @SuppressWarnings("deprecation") public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); return display.getWidth(); // API LEVEL 11 // API LEVEL 13 // Point size = new Point(); // display.getSize(size); // int width = size.x; // int height = size.y; // return width; }