use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class StorageManagerBaseTest method copyRawToFile.
/**
* Helper to copy a raw resource file to an actual specified file
*
* @param rawResId The raw resource ID of the OBB resource file
* @param outFile A File representing the file we want to copy the OBB to
* @throws NotFoundException If the resource file could not be found
*/
private void copyRawToFile(int rawResId, File outFile) throws NotFoundException {
Resources res = mContext.getResources();
InputStream is = null;
try {
is = res.openRawResource(rawResId);
} catch (NotFoundException e) {
Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId);
throw e;
}
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
assertTrue(FileUtils.copyToFile(is, outFile));
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method getDummyTriggerLayoutParams.
public static WindowManager.LayoutParams getDummyTriggerLayoutParams(Context context, int gravity) {
final Resources res = context.getResources();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams((gravity == Gravity.TOP || gravity == Gravity.BOTTOM ? ViewGroup.LayoutParams.MATCH_PARENT : 1), (gravity == Gravity.LEFT || gravity == Gravity.RIGHT ? ViewGroup.LayoutParams.MATCH_PARENT : 1), WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, PixelFormat.TRANSLUCENT);
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
lp.gravity = gravity;
return lp;
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method getPieTriggerLayoutParams.
public static WindowManager.LayoutParams getPieTriggerLayoutParams(Context context, int gravity) {
final Resources res = context.getResources();
final float mPieSize = Settings.System.getFloat(context.getContentResolver(), Settings.System.PIE_TRIGGER, 1f);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams((gravity == Gravity.TOP || gravity == Gravity.BOTTOM ? ViewGroup.LayoutParams.MATCH_PARENT : (int) (res.getDimensionPixelSize(R.dimen.pie_trigger_height) * mPieSize)), (gravity == Gravity.LEFT || gravity == Gravity.RIGHT ? ViewGroup.LayoutParams.MATCH_PARENT : (int) (res.getDimensionPixelSize(R.dimen.pie_trigger_height) * mPieSize)), WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, PixelFormat.TRANSLUCENT);
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
lp.gravity = gravity;
return lp;
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class BaseStatusBar method toggleRecentsActivity.
protected void toggleRecentsActivity() {
try {
TaskDescription firstTask = RecentTasksLoader.getInstance(mContext).getFirstTask();
Intent intent = new Intent(RecentsActivity.TOGGLE_RECENTS_INTENT);
intent.setClassName("com.android.systemui", "com.android.systemui.recent.RecentsActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
if (firstTask == null) {
if (RecentsActivity.forceOpaqueBackground(mContext)) {
ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext, R.anim.recents_launch_from_launcher_enter, R.anim.recents_launch_from_launcher_exit);
mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
} else {
// The correct window animation will be applied via the activity's style
mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
}
} else {
Bitmap first = firstTask.getThumbnail();
final Resources res = mContext.getResources();
float thumbWidth = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width);
float thumbHeight = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_height);
if (first == null) {
throw new RuntimeException("Recents thumbnail is null");
}
if (first.getWidth() != thumbWidth || first.getHeight() != thumbHeight) {
first = Bitmap.createScaledBitmap(first, (int) thumbWidth, (int) thumbHeight, true);
if (first == null) {
throw new RuntimeException("Recents thumbnail is null");
}
}
DisplayMetrics dm = new DisplayMetrics();
mDisplay.getMetrics(dm);
// calculate it here, but consider moving it elsewhere
// first, determine which orientation you're in.
// todo: move the system_bar layouts to sw600dp ?
final Configuration config = res.getConfiguration();
int x, y;
if (config.orientation == Configuration.ORIENTATION_PORTRAIT) {
float appLabelLeftMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_left_margin);
float appLabelWidth = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_width);
float thumbLeftMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_left_margin);
float thumbBgPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_bg_padding);
float width = appLabelLeftMargin + +appLabelWidth + thumbLeftMargin + thumbWidth + 2 * thumbBgPadding;
x = (int) ((dm.widthPixels - width) / 2f + appLabelLeftMargin + appLabelWidth + thumbBgPadding + thumbLeftMargin);
y = (int) (dm.heightPixels - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_height) - thumbBgPadding);
if (mLayoutDirection == View.LAYOUT_DIRECTION_RTL) {
x = dm.widthPixels - x - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width);
}
} else {
// if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
float thumbTopMargin = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_top_margin);
float thumbBgPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_bg_padding);
float textPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_text_description_padding);
float labelTextSize = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_label_text_size);
Paint p = new Paint();
p.setTextSize(labelTextSize);
float labelTextHeight = p.getFontMetricsInt().bottom - p.getFontMetricsInt().top;
float descriptionTextSize = res.getDimensionPixelSize(R.dimen.status_bar_recents_app_description_text_size);
p.setTextSize(descriptionTextSize);
float descriptionTextHeight = p.getFontMetricsInt().bottom - p.getFontMetricsInt().top;
float statusBarHeight = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
float recentsItemTopPadding = statusBarHeight;
float height = thumbTopMargin + thumbHeight + 2 * thumbBgPadding + textPadding + labelTextHeight + recentsItemTopPadding + textPadding + descriptionTextHeight;
float recentsItemRightPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_item_padding);
float recentsScrollViewRightPadding = res.getDimensionPixelSize(R.dimen.status_bar_recents_right_glow_margin);
x = (int) (dm.widthPixels - res.getDimensionPixelSize(R.dimen.status_bar_recents_thumbnail_width) - thumbBgPadding - recentsItemRightPadding - recentsScrollViewRightPadding);
y = (int) ((dm.heightPixels - statusBarHeight - height) / 2f + thumbTopMargin + recentsItemTopPadding + thumbBgPadding + statusBarHeight);
}
ActivityOptions opts = ActivityOptions.makeThumbnailScaleDownAnimation(getStatusBarView(), first, x, y, new ActivityOptions.OnAnimationStartedListener() {
public void onAnimationStarted() {
Intent intent = new Intent(RecentsActivity.WINDOW_ANIMATION_START_INTENT);
intent.setPackage("com.android.systemui");
mContext.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
}
});
intent.putExtra(RecentsActivity.WAITING_FOR_WINDOW_ANIMATION_PARAM, true);
mContext.startActivityAsUser(intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
}
return;
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Failed to launch RecentAppsIntent", e);
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class PhoneStatusBar method makeStatusBarView.
// ================================================================================
// Constructing the view
// ================================================================================
protected PhoneStatusBarView makeStatusBarView() {
final Context context = mContext;
Resources res = context.getResources();
// populates mDisplayMetrics
updateDisplaySize();
loadDimens();
mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
mStatusBarWindow = (StatusBarWindowView) View.inflate(context, R.layout.super_status_bar, null);
mStatusBarWindow.mService = this;
mStatusBarWindow.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (mExpandedVisible) {
animateCollapsePanels();
}
}
return mStatusBarWindow.onTouchEvent(event);
}
});
mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);
mStatusBarView.setStatusBar(this);
mStatusBarView.setBar(this);
mBarView = (ViewGroup) mStatusBarView;
// status bar clock
mClock = (Clock) mStatusBarView.findViewById(R.id.clock);
PanelHolder holder = (PanelHolder) mStatusBarWindow.findViewById(R.id.panel_holder);
mStatusBarView.setPanelHolder(holder);
mNotificationPanel = (NotificationPanelView) mStatusBarWindow.findViewById(R.id.notification_panel);
mNotificationPanel.setStatusBar(this);
mNotificationPanelIsFullScreenWidth = (mNotificationPanel.getLayoutParams().width == ViewGroup.LayoutParams.MATCH_PARENT);
// make the header non-responsive to clicks
mNotificationPanel.findViewById(R.id.header).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// e eats everything
return true;
}
});
if (!ActivityManager.isHighEndGfx()) {
mStatusBarWindow.setBackground(null);
mNotificationPanel.setBackground(new FastColorDrawable(context.getResources().getColor(R.color.notification_panel_solid_background)));
}
if (ENABLE_INTRUDERS) {
mIntruderAlertView = (IntruderAlertView) View.inflate(context, R.layout.intruder_alert, null);
mIntruderAlertView.setVisibility(View.GONE);
mIntruderAlertView.setBar(this);
}
if (MULTIUSER_DEBUG) {
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(R.id.header_debug_info);
mNotificationPanelDebugText.setVisibility(View.VISIBLE);
}
updateShowSearchHoldoff();
try {
boolean showNav = mWindowManagerService.hasNavigationBar();
if (DEBUG)
Slog.v(TAG, "hasNavigationBar=" + showNav);
if (showNav && !mRecreating) {
mNavigationBarView = (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
mNavigationBarView.setDisabledFlags(mDisabled);
mNavigationBarView.setBar(this);
}
} catch (RemoteException ex) {
// no window manager? good luck with that
}
// set recents activity navigation bar view
RecentsActivity.addNavigationCallback(mNavigationBarView);
// figure out which pixel-format to use for the status bar.
mPixelFormat = PixelFormat.TRANSLUCENT;
mSystemIconArea = (LinearLayout) mStatusBarView.findViewById(R.id.system_icon_area);
mStatusIcons = (LinearLayout) mStatusBarView.findViewById(R.id.statusIcons);
mNotificationIcons = (IconMerger) mStatusBarView.findViewById(R.id.notificationIcons);
mMoreIcon = mStatusBarView.findViewById(R.id.moreIcon);
mNotificationIcons.setOverflowIndicator(mMoreIcon);
mStatusBarContents = (LinearLayout) mStatusBarView.findViewById(R.id.status_bar_contents);
mTickerView = mStatusBarView.findViewById(R.id.ticker);
mPile = (NotificationRowLayout) mStatusBarWindow.findViewById(R.id.latestItems);
mPile.setLayoutTransitionsEnabled(false);
mPile.setLongPressListener(getNotificationLongClicker());
// was: expanded.findViewById(R.id.notificationLinearLayout);
mExpandedContents = mPile;
mNotificationPanelHeader = mStatusBarWindow.findViewById(R.id.header);
mClearButton = mStatusBarWindow.findViewById(R.id.clear_all_button);
mClearButton.setOnClickListener(mClearButtonListener);
mClearButton.setAlpha(0f);
mClearButton.setVisibility(View.GONE);
mClearButton.setEnabled(false);
mDateView = (DateView) mStatusBarWindow.findViewById(R.id.date);
mHasSettingsPanel = res.getBoolean(R.bool.config_hasSettingsPanel);
mHasFlipSettings = res.getBoolean(R.bool.config_hasFlipSettingsPanel);
mDateTimeView = mNotificationPanelHeader.findViewById(R.id.datetime);
if (mDateTimeView != null) {
mDateTimeView.setOnClickListener(mClockClickListener);
mDateTimeView.setEnabled(true);
}
mSettingsButton = (ImageView) mStatusBarWindow.findViewById(R.id.settings_button);
if (mSettingsButton != null) {
mSettingsButton.setOnClickListener(mSettingsButtonListener);
if (mHasSettingsPanel) {
if (mStatusBarView.hasFullWidthNotifications()) {
// the settings panel is hiding behind this button
mSettingsButton.setImageResource(R.drawable.ic_notify_quicksettings);
mSettingsButton.setVisibility(View.VISIBLE);
} else {
// there is a settings panel, but it's on the other side of the (large) screen
final View buttonHolder = mStatusBarWindow.findViewById(R.id.settings_button_holder);
if (buttonHolder != null) {
buttonHolder.setVisibility(View.GONE);
}
}
} else {
// no settings panel, go straight to settings
mSettingsButton.setVisibility(View.VISIBLE);
mSettingsButton.setImageResource(R.drawable.ic_notify_settings);
}
}
mHaloButton = (ImageView) mStatusBarWindow.findViewById(R.id.halo_button);
if (mHaloButton != null) {
mHaloButton.setOnClickListener(mHaloButtonListener);
mHaloButtonVisible = true;
updateHaloButton();
}
if (mHasFlipSettings) {
mNotificationButton = (ImageView) mStatusBarWindow.findViewById(R.id.notification_button);
if (mNotificationButton != null) {
mNotificationButton.setOnClickListener(mNotificationButtonListener);
}
}
mScrollView = (ScrollView) mStatusBarWindow.findViewById(R.id.scroll);
// less drawing during pulldowns
mScrollView.setVerticalScrollBarEnabled(false);
if (!mNotificationPanelIsFullScreenWidth) {
mScrollView.setSystemUiVisibility(View.STATUS_BAR_DISABLE_NOTIFICATION_TICKER | View.STATUS_BAR_DISABLE_NOTIFICATION_ICONS | View.STATUS_BAR_DISABLE_CLOCK);
}
mTicker = new MyTicker(context, mStatusBarView);
TickerView tickerView = (TickerView) mStatusBarView.findViewById(R.id.tickerText);
tickerView.mTicker = mTicker;
if (mHaloActive)
mTickerView.setVisibility(View.GONE);
mEdgeBorder = res.getDimensionPixelSize(R.dimen.status_bar_edge_ignore);
// set the inital view visibility
setAreThereNotifications();
// Other icons
// will post a notification
mLocationController = new LocationController(mContext);
mBatteryController = new BatteryController(mContext);
mBatteryController.addIconView((ImageView) mStatusBarView.findViewById(R.id.battery));
mNetworkController = new NetworkController(mContext);
mBluetoothController = new BluetoothController(mContext);
mSignalCluster = (SignalClusterView) mStatusBarView.findViewById(R.id.signal_cluster);
mNetworkController.addSignalCluster(mSignalCluster);
mSignalCluster.setNetworkController(mNetworkController);
mHasDockBattery = mContext.getResources().getBoolean(com.android.internal.R.bool.config_hasDockBattery);
if (mHasDockBattery) {
mDockBatteryController = new DockBatteryController(mContext);
mDockBatteryController.addIconView((ImageView) mStatusBarView.findViewById(R.id.dock_battery));
}
final boolean isAPhone = mNetworkController.hasVoiceCallingFeature();
if (isAPhone) {
mEmergencyCallLabel = (TextView) mStatusBarWindow.findViewById(R.id.emergency_calls_only);
if (mEmergencyCallLabel != null) {
mNetworkController.addEmergencyLabelView(mEmergencyCallLabel);
mEmergencyCallLabel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
mEmergencyCallLabel.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
updateCarrierLabelVisibility(false);
}
});
}
}
mCarrierLabel = (TextView) mStatusBarWindow.findViewById(R.id.carrier_label);
mShowCarrierInPanel = (mCarrierLabel != null);
if (DEBUG)
Slog.v(TAG, "carrierlabel=" + mCarrierLabel + " show=" + mShowCarrierInPanel);
if (mShowCarrierInPanel) {
mCarrierLabel.setVisibility(mCarrierLabelVisible ? View.VISIBLE : View.INVISIBLE);
// for other devices, we show whatever network is connected
if (mNetworkController.hasMobileDataFeature()) {
mNetworkController.addMobileLabelView(mCarrierLabel);
} else {
mNetworkController.addCombinedLabelView(mCarrierLabel);
}
// set up the dynamic hide/show of the label
mPile.setOnSizeChangedListener(new OnSizeChangedListener() {
@Override
public void onSizeChanged(View view, int w, int h, int oldw, int oldh) {
updateCarrierLabelVisibility(false);
}
});
}
// Quick Settings (where available, some restrictions apply)
if (mHasSettingsPanel) {
// first, figure out where quick settings should be inflated
final View settings_stub;
if (mHasFlipSettings) {
// a version of quick settings that flips around behind the notifications
settings_stub = mStatusBarWindow.findViewById(R.id.flip_settings_stub);
if (settings_stub != null) {
mFlipSettingsView = ((ViewStub) settings_stub).inflate();
mFlipSettingsView.setVisibility(View.GONE);
mFlipSettingsView.setVerticalScrollBarEnabled(false);
}
} else {
// full quick settings panel
settings_stub = mStatusBarWindow.findViewById(R.id.quick_settings_stub);
if (settings_stub != null) {
mSettingsPanel = (SettingsPanelView) ((ViewStub) settings_stub).inflate();
} else {
mSettingsPanel = (SettingsPanelView) mStatusBarWindow.findViewById(R.id.settings_panel);
}
if (mSettingsPanel != null) {
if (!ActivityManager.isHighEndGfx()) {
mSettingsPanel.setBackground(new FastColorDrawable(context.getResources().getColor(R.color.notification_panel_solid_background)));
}
}
}
// wherever you find it, Quick Settings needs a container to survive
mSettingsContainer = (QuickSettingsContainerView) mStatusBarWindow.findViewById(R.id.quick_settings_container);
// wherever you find it, Quick Settings needs a container to survive
mSettingsContainer = (QuickSettingsContainerView) mStatusBarWindow.findViewById(R.id.quick_settings_container);
if (mSettingsContainer != null) {
mQS = new QuickSettingsController(mContext, mSettingsContainer, this);
if (mSettingsPanel != null) {
mSettingsPanel.setQuickSettings(mQS);
}
mQS.setService(this);
mQS.setBar(mStatusBarView);
mQS.setupQuickSettings();
// Start observing for changes
mTilesChangedObserver = new TilesChangedObserver(mHandler);
mTilesChangedObserver.startObserving();
} else {
// fly away, be free
mQS = null;
}
}
mClingShown = !(DEBUG_CLINGS || !Prefs.read(mContext).getBoolean(Prefs.SHOWN_QUICK_SETTINGS_HELP, false));
if (!ENABLE_NOTIFICATION_PANEL_CLING || ActivityManager.isRunningInTestHarness()) {
mClingShown = true;
}
// final ImageView wimaxRSSI =
// (ImageView)sb.findViewById(R.id.wimax_signal);
// if (wimaxRSSI != null) {
// mNetworkController.addWimaxIconView(wimaxRSSI);
// }
// receive broadcasts
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
context.registerReceiver(mBroadcastReceiver, filter);
// listen for USER_SETUP_COMPLETE setting (per-user)
resetUserSetupObserver();
return mStatusBarView;
}
Aggregations