public static int getCursorEditTextAnchorPosition(Context context, int width) {
   if (ViewUtils.isInPortrait(context)) {
     return (width - context.getResources().getDimensionPixelSize(R.dimen.cursor_desired_width))
         / 2;
   }
   return context.getResources().getDimensionPixelSize(R.dimen.cursor_anchor2);
 }
  /** 对拖拽图片不同的点击事件处理 */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int X = (int) event.getX();

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        dragBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.lock_touch);
        heartView.setImageBitmap(dragBitmap);
        linearLayoutL.setBackgroundResource(R.drawable.left_bg_default);
        linearLayoutR.setBackgroundResource(R.drawable.left_bg_default);
        locationX = (int) event.getX();
        Log.i(TAG, "是否点击到位=" + isActionDown(event));
        return isActionDown(event); // 判断是否点击了滑动区�?

      case MotionEvent.ACTION_MOVE: // 保存x轴方向,绘制图画
        locationX = X;
        invalidate(); // 重新绘图
        return true;

      case MotionEvent.ACTION_UP: // 判断是否解锁成功
        dragBitmap =
            BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_slide_circle_n);
        heartView.setImageBitmap(dragBitmap);
        linearLayoutL.setBackgroundColor(getResources().getColor(R.color.transparent));
        linearLayoutR.setBackgroundResource(getResources().getColor(R.color.transparent));
        if (!unLockLeft() && !unLockRight()) { // 没有解锁成功,动画应该回滚
          flag = false;
          handleActionUpEvent(event); // 动画回滚
        }
        return true;
    }
    return super.onTouchEvent(event);
  }
 public static int getLeftDrawerWidth(Context ctx) {
   Configuration config = ctx.getResources().getConfiguration();
   int screenWidthDp = Math.round(dpToPx(ctx.getResources(), config.smallestScreenWidthDp));
   int toolbarHeight = getDimenFromAttribute(ctx, R.attr.actionBarSize);
   return Math.min(
       screenWidthDp - toolbarHeight, dimenInPx(ctx.getResources(), R.dimen.drawer_max_width));
 }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      try {
        Holder myHolder;
        if (convertView == null) {
          myHolder = new Holder();
          convertView = inflater.inflate(R.layout.item_train_xibie_list_single, null);
          myHolder.seat_grad_tv = (TextView) convertView.findViewById(R.id.seat_grad_tv);
          myHolder.ticket_price_tv = (TextView) convertView.findViewById(R.id.ticket_price_tv);
          myHolder.remain_count_tv = (TextView) convertView.findViewById(R.id.remain_count_tv);
          myHolder.iv = (ImageView) convertView.findViewById(R.id.img);
          convertView.setTag(myHolder);
        } else {
          myHolder = (Holder) convertView.getTag();
        }
        // myHolder.iv.setBackgroundResource((Integer)
        // list.get(position).get("img"));
        if (position == this.currentID && !seats.get(position).getShengyu().equals("0")) {
          myHolder.iv.setBackgroundDrawable(
              c.getResources().getDrawable(R.drawable.checkmark_icon_selected));
          hasSelected = true;
          selectedSeatIndex = position;
          // 票价格和剩余票数 随所选座位变化
          ticket_price = Float.valueOf(seats.get(selectedSeatIndex).getPrice());
          remainTicketCount = Integer.valueOf(seats.get(selectedSeatIndex).getShengyu());
          seat_Type = seats.get(selectedSeatIndex).getType();
        } else if (!hasSelected && !seats.get(position).getShengyu().equals("0")) {
          myHolder.iv.setBackgroundDrawable(
              c.getResources().getDrawable(R.drawable.checkmark_icon_selected));
          hasSelected = true;
          selectedSeatIndex = position;
          ticket_price = Float.valueOf(seats.get(selectedSeatIndex).getPrice());
          remainTicketCount = Integer.valueOf(seats.get(selectedSeatIndex).getShengyu());
          seat_Type = seats.get(selectedSeatIndex).getType();
        } else {
          myHolder.iv.setBackgroundDrawable(
              c.getResources().getDrawable(R.drawable.checkmark_icon_unselected));
        }
        myHolder.seat_grad_tv.setText(seats.get(position).getType());
        myHolder.ticket_price_tv.setText("¥" + seats.get(position).getPrice());

        if (seats.get(position).getShengyu().equals("40")) {
          myHolder.remain_count_tv.setText("票源充足 ");
        } else {
          myHolder.remain_count_tv.setText("余票" + seats.get(position).getShengyu() + "张");
        }
        if (ti.getSeat_Type().equals(seats.get(position).getType())) { // 默认选中席别与前页列表中展现的相同
          selectedSeatIndex = currentID;
        }
        if (seats.get(position).getShengyu().equals("0")) { // 余票为0,不可预订
          myHolder.seat_grad_tv.setTextColor(getResources().getColor(R.color.gray));
          myHolder.ticket_price_tv.setTextColor(getResources().getColor(R.color.gray));
          myHolder.remain_count_tv.setTextColor(getResources().getColor(R.color.gray));
          myHolder.iv.setBackgroundDrawable(c.getResources().getDrawable(R.drawable.radio));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return convertView;
    }
  private void init() {
    // TODO Auto-generated method stub
    // 滑动对象,
    LastRefreshTime = Calendar.getInstance();
    scroller = new Scroller(mContext);

    // 刷新视图顶端的的view,也就是下拉之后显示在的顶端的那部分布局
    refreshView = LayoutInflater.from(mContext).inflate(R.layout.refresh_top_item, null);
    // 指示器view
    refreshIndicatorView = (ImageView) refreshView.findViewById(R.id.indicator);
    // 刷新bar
    bar = (ProgressBar) refreshView.findViewById(R.id.progress);
    // 下拉显示text
    downTextView = (TextView) refreshView.findViewById(R.id.refresh_hint);
    // 下来显示时间
    timeTextView = (TextView) refreshView.findViewById(R.id.refresh_time);
    reFreshTimeLayout = (LinearLayout) refreshView.findViewById(R.id.refresh_time_layout);

    LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, -refreshTargetTop);
    lp.topMargin = refreshTargetTop; // 将刷新区域大小赋予布局参数的顶部margin
    lp.gravity = Gravity.CENTER; // 居中显示
    addView(refreshView, lp); // 此部分布局是加载在生成参数1的上下文所在的布局中
    downTextString = mContext.getResources().getString(R.string.refresh_down_text);
    releaseTextString = mContext.getResources().getString(R.string.refresh_release_text);
  }
 // 创建view
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   Log.i(TAG, TAG + ">>onCreateView");
   View view = null;
   if (FrameConfigure.reading_type == FrameConfigure.TYPE_NIGHT) {
     view = inflater.inflate(R.layout.night_page_news, null);
   } else {
     view = inflater.inflate(R.layout.page_news, null);
   }
   pullParent = (PullToRefreshListView) view.findViewById(R.id.page_news_listveiw);
   pullParent.setMode(Mode.BOTH);
   pullParent.setRefreshLabelTextSize(14);
   pullParent.setRefreshLabelColor(Color.GRAY);
   pullParent.setLoadingDrawable(
       context.getResources().getDrawable(R.drawable.xlistview_arrow), Mode.PULL_FROM_START);
   pullParent.setLoadingPregressDrawable(
       context.getResources().getDrawable(R.drawable.xlistview_loadings), Mode.PULL_FROM_START);
   pullParent.setLoadingPregressWidthAndHeight(
       ScreenUtil.dip2px(context, 32), ScreenUtil.dip2px(context, 32), Mode.PULL_FROM_START);
   listView = pullParent.getRefreshableView();
   page_news_loading = (LinearLayout) view.findViewById(R.id.page_news_loading);
   linear_reload = (LinearLayout) view.findViewById(R.id.linear_reload);
   rela_loading = (RelativeLayout) view.findViewById(R.id.rela_loading);
   ibtn_reloading = (ImageButton) view.findViewById(R.id.ibtn_reloading);
   setupListener();
   return view;
 }
  public DownloadIconsDialog(final Context context, final boolean changeSettings) {
    super(context);
    mChangeSettingsEnabled = changeSettings;

    setTitle(R.string.msg_download_icons_dialog_title);
    setCancelable(true);
    setIcon(android.R.drawable.ic_dialog_info);

    final TextView message = new TextView(context);
    String str;
    try {
      str = FileUtil.writeToString(context.getResources().openRawResource(R.raw.icons_pack));
    } catch (Exception e) {
      str = e.toString();
    }
    final SpannableString s = new SpannableString(Html.fromHtml(str));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(5, 5, 5, 5);
    message.setTextColor(context.getResources().getColorStateList(R.color.dialog_text_color));
    message.setLinkTextColor(context.getResources().getColorStateList(R.color.links_color));
    setView(message);

    setButton(AlertDialog.BUTTON_POSITIVE, context.getText(android.R.string.yes), this);
    setButton(AlertDialog.BUTTON_NEGATIVE, context.getText(android.R.string.no), this);
    setOnCancelListener(this);
  }
 protected void onDraw(Canvas canvas)
 {
     this;
     JVM INSTR monitorenter ;
     c.set(getThumbOffset(), getHeight() / 2 - f / 4, getWidth() - getThumbOffset(), getHeight() / 2 + f / 4);
     d.setColor(0xff888888);
     canvas.drawRect(c, d);
     int i = getWidth();
     int j = getHeight();
     canvas.drawBitmap(e, i / 2 - e.getWidth() / 2, j / 2 - e.getHeight() / 2, null);
     if (getProgress() > 500)
     {
         c.set(getWidth() / 2, getHeight() / 2 - f / 2, (getWidth() / 2 + (getWidth() * (getProgress() - 500)) / 1000) - ((getProgress() - 500) * getThumbOffset()) / 500, getHeight() / 2 + f / 2);
         d.setColor(g.getResources().getColor(0x7f0f0007));
         canvas.drawRect(c, d);
     }
     if (getProgress() < 500)
     {
         c.set((getWidth() / 2 - (getWidth() * (500 - getProgress())) / 1000) + ((500 - getProgress()) * getThumbOffset()) / 500, getHeight() / 2 - f / 2, getWidth() / 2, getHeight() / 2 + f / 2);
         d.setColor(g.getResources().getColor(0x7f0f0007));
         canvas.drawRect(c, d);
     }
     super.onDraw(canvas);
     this;
     JVM INSTR monitorexit ;
     return;
     canvas;
     throw canvas;
 }
 public static Drawable getDrawable(@NonNull Context context, @DrawableRes int drawableRes) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
     return context.getResources().getDrawable(drawableRes, context.getTheme());
   } else {
     return context.getResources().getDrawable(drawableRes);
   }
 }
Exemple #10
0
  // Must be called before setContentView()
  public static void changeLanguage(Context context, int lang) {
    String language = null;
    String country = null;

    switch (lang) {
      case 1:
        language = "zh";
        country = "CN";
        break;
      case 2:
        language = "zh";
        country = "TW";
        break;
      default:
        language = "en";
        country = "US";
        break;
    }

    Locale locale = new Locale(language, country);
    Configuration conf = context.getResources().getConfiguration();
    conf.locale = locale;
    context
        .getApplicationContext()
        .getResources()
        .updateConfiguration(conf, context.getResources().getDisplayMetrics());
  }
  /** Sets up a notification shortcut in the system bar */
  public static void setupNotification() {
    Context context = ApplicationContext.getInstance();
    String notificationService = Context.NOTIFICATION_SERVICE;
    mNotificationManager = (NotificationManager) context.getSystemService(notificationService);
    Intent notificationIntent = new Intent(context, MainFragmentActivity.class);
    PendingIntent contentIntent =
        PendingIntent.getActivity(
            context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app))
              .setWhen(0);
    else
      mBuilder =
          new NotificationCompat.Builder(ApplicationContext.getInstance())
              .setSmallIcon(R.drawable.ic_stat_notification)
              .setContentTitle(context.getResources().getText(R.string.app_name))
              .setContentText(context.getResources().getText(R.string.go_to_app));

    mBuilder.setContentIntent(contentIntent);
    // mId allows you to update the notification later on.
    int mId = 1;
    Notification shortcutNotification = mBuilder.build();
    shortcutNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(mId, shortcutNotification);

    ApplicationContext.getInstance().notificationIsShowing = true;
  }
Exemple #12
0
 /**
  * 图片数
  *
  * @param selNum
  */
 public static void setSendText(int selNum) {
   if (selNum == 0) {
     mFinishTv.setText(mContext.getResources().getString(R.string.send));
   } else {
     mFinishTv.setText(mContext.getResources().getString(R.string.send) + "(" + selNum + ")");
   }
 }
Exemple #13
0
  public boolean addImages(Context context, Spannable spannable) {
    Pattern refImg = Pattern.compile("\\Q[img src=\\E([a-zA-Z0-9_]+?)\\Q/]\\E");
    boolean hasChanges = false;

    Matcher matcher = refImg.matcher(spannable);
    while (matcher.find()) {
      boolean set = true;
      for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) {
        if (spannable.getSpanStart(span) >= matcher.start()
            && spannable.getSpanEnd(span) <= matcher.end()) {
          spannable.removeSpan(span);
        } else {
          set = false;
          break;
        }
      }
      String resname = spannable.subSequence(matcher.start(1), matcher.end(1)).toString().trim();
      int id = context.getResources().getIdentifier(resname, "drawable", context.getPackageName());
      Drawable icon = context.getResources().getDrawable(id); // ,this.getTheme());
      icon.setBounds(0, 0, tv_test1.getLineHeight(), tv_test1.getLineHeight());
      if (set) {
        hasChanges = true;
        spannable.setSpan(
            new ImageSpan(icon, ImageSpan.ALIGN_BASELINE),
            matcher.start(),
            matcher.end(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
    }
    return hasChanges;
  }
  public void init(
      @NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) {
    final Context context = view.getContext();
    final int defColor = baseTextPaint.getColor();
    final int defPadding =
        context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_default_padding);
    final float minTextSize =
        context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_min_size);

    if (attrs == null) {
      for (DragDirection direction : DragDirection.values()) {
        final Text text = new Text(direction, view, minTextSize);
        text.init(baseTextPaint, null, DEF_SCALE, defColor, DEF_ALPHA, defPadding);
        texts.put(direction, text);
      }
      return;
    }
    final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.DirectionText);
    final float scale = array.getFloat(R.styleable.DirectionText_directionTextScale, DEF_SCALE);
    final float alpha = array.getFloat(R.styleable.DirectionText_directionTextAlpha, DEF_ALPHA);
    final int color = array.getColor(R.styleable.DirectionText_directionTextColor, defColor);
    final int padding =
        array.getDimensionPixelSize(R.styleable.DirectionText_directionTextPadding, defPadding);
    for (DragDirection direction : DragDirection.values()) {
      final Text text = new Text(direction, view, minTextSize);
      text.init(baseTextPaint, array, scale, color, alpha, padding);
      texts.put(direction, text);
    }
    array.recycle();
  }
  @Override
  public View getGroupView(
      int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    View v = convertView;
    GroupHolder holder = new GroupHolder();

    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      v = inflater.inflate(R.layout.fragment_upload_review_group_item, null);
      holder.title = (TextView) v.findViewById(R.id.groupListHeader);
      holder.imageView = (ImageView) v.findViewById(R.id.statusImage);
      v.setTag(holder);
    } else {
      holder = (GroupHolder) v.getTag();
    }

    holder.title.setText(
        String.format(
            mContext.getResources().getString(R.string.label_chapter_title_detailed),
            getGroup(groupPosition).getId()));
    // TODO: this will be expensive we need a better way to keep track of what's been viewed.
    // perhaps we can check when the user clicks on an item and then cache the value. we could also
    // cache the value when laoding the questions.
    if (getGroup(groupPosition).isViewedCached()) {
      holder.imageView.setImageDrawable(
          mContext.getResources().getDrawable(R.drawable.ic_check_small));
    } else {
      holder.imageView.setImageDrawable(
          mContext.getResources().getDrawable(R.drawable.ic_check_small_disabled));
    }
    return v;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_no_location);

    final Context context = this;
    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
    dialog.setMessage(context.getResources().getString(R.string.gps_network_not_enabled));
    dialog.setPositiveButton(
        context.getResources().getString(R.string.open_location_settings),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface paramDialogInterface, int paramInt) {
            Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            context.startActivity(myIntent);
            // get gps
            finish();
          }
        });
    dialog.setNegativeButton(
        context.getString(R.string.cancel_location_settings),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface paramDialogInterface, int paramInt) {
            finish();
          }
        });
    dialog.show();
  }
Exemple #17
0
  /**
   * 绘制导航标签
   *
   * @param context
   * @param total 总的位置信息
   * @param currentPosition 当前位置
   * @param basicImageId 基本的图形信息
   * @param currentImageId 当前位置所要显示的图形信息
   * @param marginSpace 导航条圆点中间的间距
   * @return
   */
  public static Bitmap drawNavigator(
      Context context,
      int total,
      int currentPosition,
      int basicImageId,
      int currentImageId,
      int marginSpace) {
    if (total <= 0) {
      total = 1;
    }
    int current = currentPosition;
    Drawable drawable = context.getResources().getDrawable(currentImageId);
    int imageWidth = drawable.getIntrinsicWidth();
    int imageHeight = drawable.getIntrinsicHeight();
    // 生成最终要绘制的bitmap,长度是总的标签数乘以图片本身的宽度
    Bitmap navigatorBitmap =
        Bitmap.createBitmap((imageWidth + 6) * total, imageHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(navigatorBitmap);
    // 往画板上填充基本的图像内容
    Bitmap basic = BitmapFactory.decodeResource(context.getResources(), basicImageId);
    for (int i = 0; i < total; i++) {
      canvas.drawBitmap(basic, (marginSpace + imageWidth) * i, 0, null);
    }
    drawable.setBounds(
        (imageWidth + marginSpace) * (current - 1),
        0,
        (imageWidth + marginSpace) * current - marginSpace,
        imageHeight);
    drawable.draw(canvas);
    return navigatorBitmap;
  }
    @Override
    public void onStart() {
        final Context context = getContext();
        mTwilightManager = getLocalService(TwilightManager.class);
        final PowerManager powerManager =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);

        context.registerReceiver(mDockModeReceiver,
                new IntentFilter(Intent.ACTION_DOCK_EVENT));
        context.registerReceiver(mBatteryReceiver,
                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

        mConfiguration.setToDefaults();

        mDefaultUiModeType = context.getResources().getInteger(
                com.android.internal.R.integer.config_defaultUiModeType);
        mCarModeKeepsScreenOn = (context.getResources().getInteger(
                com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
        mDeskModeKeepsScreenOn = (context.getResources().getInteger(
                com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
        mTelevision = context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_TELEVISION) ||
            context.getPackageManager().hasSystemFeature(
                    PackageManager.FEATURE_LEANBACK);
        mWatch = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);

        mNightMode = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO);

        mTwilightManager.registerListener(mTwilightListener, mHandler);

        publishBinderService(Context.UI_MODE_SERVICE, mService);
    }
Exemple #19
0
  @StressTest
  @UiThreadTest
  public void testUpdateRequest() {
    MemoryLogger memoryLogger = new MemoryLogger("testUpdateRequest", 100);

    viewManager.setKeyboardLayout(KeyboardLayout.TWELVE_KEYS);

    final int actions = 500;
    Context context = getInstrumentation().getTargetContext();

    SessionExecutor session = SessionExecutor.getInstance(context);
    KeyboardSpecification specification = viewManager.getKeyboardSpecification();
    Request request =
        MozcUtil.getRequestBuilder(
                context.getResources(), specification, context.getResources().getConfiguration())
            .build();
    List<TouchEvent> touchEventList = Collections.emptyList();

    memoryLogger.logMemory("start");
    for (int i = 0; i < actions; i++) {
      session.updateRequest(request, touchEventList);
      // updateRequest sends asynchronous message to server. So we need to wait a moment
      // for server processing.
      sleep(100);

      memoryLogger.logMemoryInterval();
    }
    memoryLogger.logMemory("end");
  }
  /**
   * Get the white icon corresponding to a poiType.
   *
   * @param poiType the PoiType or null for notes.
   * @return The white icon.
   */
  public Drawable getIconWhite(PoiType poiType) {
    Bitmap myBitmap =
        BitmapFactory.decodeResource(
            context.getResources(),
            poiType == null ? R.drawable.open_book : getIconDrawableId(poiType));
    myBitmap = myBitmap.copy(myBitmap.getConfig(), true);

    int[] allpixels = new int[myBitmap.getHeight() * myBitmap.getWidth()];

    myBitmap.getPixels(
        allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

    for (int i = 0; i < myBitmap.getHeight() * myBitmap.getWidth(); i++) {
      if (allpixels[i] != 0) {
        int A = Color.alpha(allpixels[i]);
        // inverting byte for each R/G/B channel
        int R = 255 - Color.red(allpixels[i]);
        int G = 255 - Color.green(allpixels[i]);
        int B = 255 - Color.blue(allpixels[i]);
        // set newly-inverted pixel to output image
        allpixels[i] = Color.argb(A, R, G, B);
      }
    }

    myBitmap.setPixels(
        allpixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());

    return new BitmapDrawable(context.getResources(), myBitmap);
  }
  public static CallContact buildUserContact(Context c) {
    CallContact result = null;
    try {
      Cursor mProfileCursor =
          c.getContentResolver().query(Profile.CONTENT_URI, PROFILE_PROJECTION, null, null, null);
      if (mProfileCursor != null) {
        if (mProfileCursor.moveToFirst()) {
          String key = mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.LOOKUP_KEY));
          String displayName =
              mProfileCursor.getString(mProfileCursor.getColumnIndex(Profile.DISPLAY_NAME_PRIMARY));

          if (displayName == null || displayName.isEmpty())
            displayName = c.getResources().getString(R.string.me);
          result =
              new CallContact(
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile._ID)),
                  key,
                  displayName,
                  mProfileCursor.getLong(mProfileCursor.getColumnIndex(Profile.PHOTO_ID)),
                  new ArrayList<Phone>(),
                  "",
                  true);
        }
        mProfileCursor.close();
      }
    } catch (Exception e) {
      Log.w(TAG, e);
    }
    return result == null
        ? new CallContact(
            -1, null, c.getResources().getString(R.string.me), 0, new ArrayList<Phone>(), "", true)
        : result;
  }
  @SuppressLint("NewApi")
  public Drawable getDrawable(int resId) {
    Drawable originDrawable = context.getResources().getDrawable(resId);
    if (mResources == null || isDefaultSkin) {
      return originDrawable;
    }
    String resName = context.getResources().getResourceEntryName(resId);

    int trueResId = mResources.getIdentifier(resName, "drawable", skinPackageName);

    Drawable trueDrawable = null;
    try {
      L.e("ttgg", "SDK_INT = " + android.os.Build.VERSION.SDK_INT);
      if (android.os.Build.VERSION.SDK_INT < 22) {
        trueDrawable = mResources.getDrawable(trueResId);
      } else {
        trueDrawable = mResources.getDrawable(trueResId, null);
      }
    } catch (NotFoundException e) {
      e.printStackTrace();
      trueDrawable = originDrawable;
    }

    return trueDrawable;
  }
 public DashboardViewAttr(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray ta =
       context.obtainStyledAttributes(attrs, R.styleable.DashboardView, defStyleAttr, 0);
   mTikeCount = ta.getInt(R.styleable.DashboardView_tikeCount, 48);
   mTextSize =
       ta.getDimensionPixelSize(
           PxUtils.spToPx(R.styleable.DashboardView_android_textSize, context), 24);
   mText = ta.getString(R.styleable.DashboardView_android_text);
   //        progressHeight =
   // ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_progressHeight,context), 20);
   unit = ta.getString(R.styleable.DashboardView_Unit);
   textColor =
       ta.getColor(
           R.styleable.DashboardView_textColor,
           context.getResources().getColor(R.color.textColor));
   background = ta.getColor(R.styleable.DashboardView_backgroundColor, 0);
   startColor = ta.getColor(R.styleable.DashboardView_startProgressColor, 0);
   endColor = ta.getColor(R.styleable.DashboardView_endProgressColor, 0);
   startNum = ta.getInt(R.styleable.DashboardView_startNumber, 0);
   maxNum = ta.getInt(R.styleable.DashboardView_maxNumber, 120);
   padding = ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_padding, context), 0);
   progressColor =
       ta.getColor(
           R.styleable.DashboardView_progressColor,
           context.getResources().getColor(R.color.skyblue));
   ta.recycle();
 }
  private void criarSeletor(Integer position, View view) {
    LinearLayout ln = (LinearLayout) view.findViewById(R.id.listln);
    TextView tx = (TextView) view.findViewById(R.id.textmenu);

    if (itemPosition.equals(
        position)) { // criando seletor e setando a cor do texto mediante a selecao do usuario
      ln.setBackgroundColor(context.getResources().getColor(R.color.preto_claro));
      switch (itemPosition) {
        case 1:
          tx.setTextColor(view.getResources().getColor(R.color.verde));
          break;

        case 2:
          tx.setTextColor(view.getResources().getColor(R.color.vermelho_claro));
          break;
        case 3:
          tx.setTextColor(view.getResources().getColor(R.color.azul_piscina));
          break;

        default:
          tx.setTextColor(view.getResources().getColor(R.color.branco));
          break;
      }
    } else {
      ln.setBackgroundColor(context.getResources().getColor(R.color.preto));
      tx.setTextColor(view.getResources().getColor(R.color.branco));
    }
  }
  public void RefreshTotalChecked(
      TextView totalCheckedTextView, TextView tvName, LinearLayout layout, int position) {
    ShoppingList shoppingList = shoppingLists.get(position);
    String text =
        DataManager.shoppingListGetChecked(shoppingList) + "/" + shoppingList.getItems().size();
    totalCheckedTextView.setText(text);

    boolean shoppingListIsChecked = DataManager.shoppingListIsChecked(shoppingList);
    if (shoppingListIsChecked) {
      DataManager.setShoppingListIsChecked(shoppingList, true);
      layout
          .getBackground()
          .setColorFilter(
              context.getResources().getColor(R.color.itemListBackgroundChecked),
              PorterDuff.Mode.MULTIPLY);
      tvName.setPaintFlags(tvName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    } else {
      DataManager.setShoppingListIsChecked(shoppingList, false);
      layout
          .getBackground()
          .setColorFilter(
              context.getResources().getColor(R.color.itemListBackground),
              PorterDuff.Mode.MULTIPLY);
      tvName.setPaintFlags(tvName.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
    }
  }
 public static AlertDialog msgBoxYesNo(
     Context context,
     String title,
     String msg,
     final DialogInterface.OnClickListener listener,
     boolean canceledOnTouchOutside) {
   AlertDialog msgAlert = new AlertDialog.Builder(context).create();
   msgAlert.setTitle(title);
   msgAlert.setCanceledOnTouchOutside(canceledOnTouchOutside);
   msgAlert.setMessage(msg);
   msgAlert.setButton(
       DialogInterface.BUTTON_POSITIVE,
       context.getResources().getString(R.string.yes),
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           listener.onClick(dialog, MSG_BUTTON_YES);
         }
       });
   msgAlert.setButton(
       DialogInterface.BUTTON_NEGATIVE,
       context.getResources().getString(R.string.no),
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           listener.onClick(dialog, MSG_BUTTON_NO);
         }
       });
   msgAlert.show();
   return msgAlert;
 }
  /**
   * Creates a new CaptureRenderer, based on an Inside3dRenderer with the given mesh as Skybox.
   *
   * @param context - Context of the application.
   * @param skybox
   * @param cameraManager
   */
  public CaptureRenderer(Context context, Cube skybox, CameraManager cameraManager) {
    // based on Inside3dRenderer. We are inside a skybox.
    super(context);
    mSkybox = skybox;
    super.setSurroundingMesh(mSkybox);
    super.setFovDeg(DEFAULT_FOV_DEG);

    // init attributes
    mCameraManager = cameraManager;
    mCameraManager.addSnapshotEventListener(this);
    mContext = context;

    mMarkerBitmap = BitmapDecoder.safeDecodeBitmap(mContext.getResources(), MARKER_RESSOURCE_ID);
    mContourBitmap = BitmapDecoder.safeDecodeBitmap(mContext.getResources(), CONTOUR_RESSOURCE_ID);

    // if auto samplig enabled
    if (mSampleRate == 0) {
      mSampleRate = (int) mCameraManager.getCameraResolution();
      mSampleRate = (int) (ceilPowOf2(mSampleRate) / SNAPSHOT_AUTO_SAMPLE_RATIO);
    }

    mViewMatrix = new float[16];
    Matrix.setIdentityM(mViewMatrix, 0);

    // create dots and snapshot lists
    mSnapshots = new ArrayList<Snapshot3D>();
    mDots = new LinkedList<Snapshot3D>();
    mContours43 = new LinkedList<Snapshot3D>();
    mContours34 = new LinkedList<Snapshot3D>();
    mContours = mContours43;
    mTargetsLock = new ReentrantLock();
    mSnapshotsLock = new ReentrantLock();
  }
  public static NotificationCompat.Builder getBaseBuilder(Context ctx, boolean setAutoCancel) {
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(ctx);
    notifBuilder.setSound(defaultSoundUri);
    notifBuilder.setAutoCancel(setAutoCancel);
    notifBuilder.setSmallIcon(R.drawable.ic_notification);

    // Notification styles changed since Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      int color;
      // We have to check the M version for the deprecation of the method getColor()
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        color = ctx.getResources().getColor(R.color.highlight_light);
      } else {
        color = ctx.getResources().getColor(R.color.highlight_light);
      }
      notifBuilder.setColor(color);
    } else {
      // in older versions, we show the App logo
      notifBuilder.setLargeIcon(
          BitmapFactory.decodeResource(ctx.getResources(), MobileLearning.APP_LOGO));
    }

    return notifBuilder;
  }
Exemple #29
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    TaskViewHolder holder;
    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(row, null);
      holder = new TaskViewHolder();
      convertView.setTag(holder);
    } else {
      holder = (TaskViewHolder) convertView.getTag();
    }

    if ((tours == null) || ((position + 1) > tours.size()))
      return convertView; // Can't extract item

    Tour obj = tours.get(position);
    holder.image = (ImageView) convertView.findViewById(R.id.tourImage);
    Drawable img =
        mContext
            .getResources()
            .getDrawable(
                mContext
                    .getResources()
                    .getIdentifier(obj.getImage(), "drawable", mContext.getPackageName()));
    holder.image.setImageDrawable(img);
    holder.name = (TextView) convertView.findViewById(R.id.tourNameLbl);
    holder.name.setText(obj.getName());
    holder.totalHours = (TextView) convertView.findViewById(R.id.totalHoursLbl);
    holder.totalHours.setText(obj.getTotalHours() + "h");
    holder.totalKms = (TextView) convertView.findViewById(R.id.totalKmsLbl);
    holder.totalKms.setText(obj.getTotalKms() + "Km");

    return convertView;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.post_fragment, container, false);

    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);

    mProgressLoadMore = (ProgressBar) rootView.findViewById(R.id.progress);
    mEmptyView = rootView.findViewById(R.id.empty_view);
    mEmptyViewTitle = (TextView) mEmptyView.findViewById(R.id.title_empty);
    mEmptyViewImage = (ImageView) mEmptyView.findViewById(R.id.image_empty);

    Context context = getActivity();
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));

    int spacingVertical = context.getResources().getDimensionPixelSize(R.dimen.reader_card_gutters);
    int spacingHorizontal = context.getResources().getDimensionPixelSize(R.dimen.content_margin);
    mRecyclerView.addItemDecoration(new RecyclerItemDecoration(spacingHorizontal, spacingVertical));

    // mEmptyViewImage.setVisibility(View.VISIBLE);
    // mEmptyView.setVisibility(View.VISIBLE);

    return rootView;
  }