@Override public void handleMessage(Message msg) { Context context = getContext(); if (context == null) { Log.e(TAG, "error handling message, getContext() returned null"); return; } switch (msg.arg1) { case COMMAND_CHANGE_TITLE: if (context instanceof Activity) { ((Activity) context).setTitle((String) msg.obj); } else { Log.e(TAG, "error handling message, getContext() returned no Activity"); } break; case COMMAND_TEXTEDIT_HIDE: if (mTextEdit != null) { mTextEdit.setVisibility(View.GONE); InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0); } break; default: if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) { Log.e(TAG, "error handling message, command is " + msg.arg1); } } }
public MapView(Context ctx, boolean allowNetAccess, int mode) { super(ctx); Display display; this.allowNetAccess = allowNetAccess; geoUtils = new GeoUtils(mode); setBackgroundColor(0xFF555570); display = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); scrWidth = display.getWidth(); scrHeight = display.getHeight(); setMinimumHeight(scrWidth); setMinimumWidth(scrHeight); tileWidth = (int) Math.ceil(scrWidth / 256.0) + 1; tileHeight = (int) Math.ceil(scrHeight / 256.0) + 1; gestureDetector = new GestureDetector(ctx, new GestureListener()); zoomOutButton = new Button(ctx); zoomOutButton.setText(" - "); zoomOutButton.setOnClickListener(this); zoomInButton = new Button(ctx); zoomInButton.setText(" + "); zoomInButton.setOnClickListener(this); updateUI(true); addView(zoomOutButton); addView(zoomInButton); }
// Startup public SDLSurface(Context context) { super(context); getHolder().addCallback(this); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); setOnKeyListener(this); setOnTouchListener(this); mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); // Some arbitrary defaults to avoid a potential division by zero mWidth = 1.0f; mHeight = 1.0f; }
// Startup public SDLSurface(Context context) { super(context); getHolder().addCallback(this); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); setOnKeyListener(this); setOnTouchListener(this); mSensorManager = (SensorManager) context.getSystemService("sensor"); }
@Override public void handleMessage(Message msg) { Context context = getContext(); if (context == null) { Log.e(TAG, "error handling message, getContext() returned null"); return; } switch (msg.arg1) { case COMMAND_CHANGE_TITLE: if (context instanceof Activity) { ((Activity) context).setTitle((String) msg.obj); } else { Log.e(TAG, "error handling message, getContext() returned no Activity"); } break; case COMMAND_TEXTEDIT_HIDE: if (mTextEdit != null) { mTextEdit.setVisibility(View.GONE); InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0); } break; case COMMAND_SET_KEEP_SCREEN_ON: { Window window = ((Activity) context).getWindow(); if (window != null) { if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) { window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else { window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } } break; } default: if ((context instanceof SDLActivity) && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) { Log.e(TAG, "error handling message, command is " + msg.arg1); } } }
@Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.row, null); } Message m = items.get(position); // if (m != null) { m.createColorFromString(m.from); TextView tt = (TextView) v.findViewById(R.id.username); TextView bt = (TextView) v.findViewById(R.id.message); if (isMonospaced) { tt.setTypeface(Typeface.MONOSPACE); bt.setTypeface(Typeface.MONOSPACE); } tt.setText(m.getFrom()); tt.setTextColor(m.color); bt.setText(m.getMessage()); // } return v; }