صفحه 2 از 4 اولاول 1234 آخرآخر
نمایش نتایج 41 تا 80 از 128

نام تاپیک: این هم کد

  1. #41
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    چک می کند که آیا برای فعالیت این اینتنت برنامه ای وجود دارد یا خیر:

    	public static boolean isIntentAvailable(final Context context, final Intent intent) {
    final PackageManager packageManager = context.getPackageManager();
    List<ResolveInfo> list =
    packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
    }

  2. #42
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    چک می کند که آیا برنامه این دسترسی را دارد یا خیر :

        public static boolean hasPermissions(Context context, String... permissions) {
    for (String p : permissions)
    if (context.checkCallingOrSelfPermission(p) == PackageManager.PERMISSION_DENIED)
    return false;
    return true;
    }// hasPermissions()
    }
    آخرین ویرایش به وسیله dasssnj : جمعه 02 خرداد 1393 در 11:42 صبح

  3. #43
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    آیا گوشیم فلاش داره؟

    public static boolean hasFlash(Context con) {
    boolean mHasFlash = false;
    try {
    PackageManager pm = con.getPackageManager();
    mHasFlash = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ FLASH);
    return mHasFlash;
    } catch (Throwable t) {
    mHasFlash = null;
    return false;
    }
    }
    آخرین ویرایش به وسیله dasssnj : جمعه 02 خرداد 1393 در 11:42 صبح

  4. #44
    کاربر دائمی آواتار saeed_g21
    تاریخ عضویت
    مرداد 1388
    محل زندگی
    تبریز
    پست
    1,078

    نقل قول: این هم کد

    کدی برای حذف برنامه


    Uri packageURI = Uri.parse("package:com.android.myapp");
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    startActivity(uninstallIntent);


    مانیفیست
    <activity android:name=".UninstallerActivity">    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.DELETE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="package" />
    </intent-filter>
    </activity>

  5. #45
    کاربر دائمی آواتار saeed_g21
    تاریخ عضویت
    مرداد 1388
    محل زندگی
    تبریز
    پست
    1,078

    نقل قول: این هم کد

    کدی برای نصب برنامه

     fileName = Environment.getExternalStorageDirectory() + "/myApp.apk";Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
    startActivity(intent);


    مانیفیست
    <activity android:name=".PackageInstallerActivity">    <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="content" />
    <data android:scheme="file" />
    <data android:mimeType="application/vnd.android.package-archive" />
    </intent-filter>
    </activity>

  6. #46

    نقل قول: این هم کد

    خروج از برنامه : فقط AppExit() را در listener هر دکمه ای که میخواهید قرار دهید


    public void AppExit() {
    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    }

  7. #47
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    تشخیص روت بودن گوشی:

    	public static boolean isRooted() {
    try {
    Process process = Runtime.getRuntime().exec("su");
    DataOutputStream os = new DataOutputStream(
    process.getOutputStream());
    os.writeBytes("exit\n");
    os.flush();
    process.waitFor();
    int i = process.exitValue();
    if (i == 0)
    return true;
    else
    return false;


    } catch (Exception e) {
    }
    return false;
    }

  8. #48

    کنترل نمای تمام صفحه (fuul screen ) توسط کد برنامه

    بدین صورت

    : WindowManager.LayoutParams attrs = this.getWindow().getAttributes();

    //go full screen
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    this.getWindow().setAttributes(attrs);

    // go non-full sceen
    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.getWindow().setAttributes(attrs);


    برای نمایش یا مخفی کردن ActionBar هم همون طور که گفتید باید قبل از setContentView این کار رو کرد ،

    requestWindowFeature(Window.FEATURE_NO_TITLE);

  9. #49

    نقل قول: این هم کد

    این هم کد تمام صفحه کردن Activity و عکس آن
    WindowManager.LayoutParams attrs = this.getWindow().getAttributes();

    //تمام صفحه کردن
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    this.getWindow().setAttributes(attrs);

    //خروج از حالت تمام صفحه
    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.getWindow().setAttributes(attrs);

  10. #50

    نقل قول: این هم کد

    نقل قول نوشته شده توسط moralschool مشاهده تاپیک
    اگه بخوای از یه پوشه مثلا از raw فراخوانی کنی میتونی این کد رو در یه دکمه قرار بدی و براحتی موزیک مورد نظرت رو بعنوان زنگ موبایل قرار بدی :


    byte[] buffer = null;
    InputStream fIn = getBaseContext().getResources().openRawResource(
    R.raw.zang1);
    int size = 0;

    try {
    size = fIn.available();
    buffer = new byte[size];
    fIn.read(buffer);
    fIn.close();
    } catch (IOException e) {
    return false;
    }

    String path = Environment.getExternalStorageDirectory().getPath( )
    + "/media/audio/ringtones/";

    String filename = "zang1.mp3";

    boolean exists = (new File(path)).exists();
    if (!exists) {
    new File(path).mkdirs();
    }

    FileOutputStream save;
    try {
    save = new FileOutputStream(path + filename);
    save.write(buffer);
    save.flush();
    save.close();
    } catch (FileNotFoundException e) {
    return false;
    } catch (IOException e) {
    return false;
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
    Uri.parse("file://" + path + filename)));

    File k = new File(path, filename);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE, filename);
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");

    // This method allows to change Notification and Alarm tone also. Just
    // pass corresponding type as parameter
    if (RingtoneManager.TYPE_RINGTONE == type) {
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
    } else if (RingtoneManager.TYPE_NOTIFICATION == type) {
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
    } else if (RingtoneManager.TYPE_ALARM == type) {
    values.put(MediaStore.Audio.Media.IS_ALARM, true);
    }

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
    .getAbsolutePath());
    Uri newUri = Zang.this.getContentResolver().insert(uri, values);
    RingtoneManager.setActualDefaultRingtoneUri(Zang.t his, type,
    newUri);

    // Insert it into the database
    this.getContentResolver()
    .insert(MediaStore.Audio.Media.getContentUriForPat h(k
    .getAbsolutePath()), values);

    return true;
    سلام
    وقتی این کد را در یک دکمه بعد از setonclicklistener قرار بدی خیلی از کدها را نمیشناسه و نمیشه import کرد
    باید چیکار کرد؟

  11. #51

    نقل قول: این هم کد

    نمایش یک Toast بیشتر از زمان مشخص شده

    این کد رو پیدا کردم به نظرم مفید اومد

    در حالت عادی Toast دو مقدار زمانی میتونه داشته باشه، short برابر 2000 میلی ثانیه (2 ثانیه) و long برابر 3500 میلی ثانیه (3.5 ثانیه)

    اگر بخواین چند تا Toast رو پشت سر هم نشون بدید بینشون معلوم میشه که toast داره عوض میشه

    با کد زیر یک Toast به مدت 10 ثانیه بدون مشکل در نمایش نشون بدید !!!

    		final Toast tag = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);

    tag.show();


    new CountDownTimer(9000, 1000)
    {


    public void onTick(long millisUntilFinished) {tag.show();}
    public void onFinish() {tag.show();}


    }.start();

  12. #52
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    نمایش توست دقیقا زیر ویو مرد نظر:(مثل ایتم های اکشن بار)

    public static void showToastUnder(View v){
    Toast toast = Toast.makeText(v.getContext(),
    v.getContentDescription(), Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.LEFT | Gravity.TOP, v.getLeft(),
    v.getBottom() + v.getBottom() / 2);
    toast.show();
    }

  13. #53
    کاربر جدید آواتار Erfan-APK
    تاریخ عضویت
    خرداد 1393
    محل زندگی
    کرج
    پست
    19

    نقل قول: این هم کد

    اینم کد لرزاندن گوشی اندرویدی (=ویبره )
    اول پرمیشن رو تو منیفست اضافه کنید:
    <uses-permission android:name="android.permission.VIBRATE"/>


    اینم خود ویبره(هرجا بخواید می تونید بنویسید)

    Vibrator vibrator = (Vibrator)getSystemService(main.VIBRATOR_SERVICE); 
    ///زمان به میلی ثانیه = 2ثانیه تو این مثال
    vibrator.vibrate(2000);
    // الگوی ویبره که تو این مثال به صورت افزایشیه
    long pattern[]={0,800,200,1200,300,2000,400,4000};
    // -1 = اگر نمیخواین دوباره ویبره تکرار بشه
    vibrator.vibrate(pattern,-1);
    آخرین ویرایش به وسیله Erfan-APK : شنبه 24 خرداد 1393 در 18:38 عصر

  14. #54
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    اینم پیدا کردن عدد رندم بین دو عدد (البته مربوط به طراحی الگوریتم میشه و اختصاصی اندروید نیست):
        public static int rand(int a, int b) {
    if (a == b)
    return -1;
    else if (a > b)
    return -1;
    else if (b - a == 1)
    return -1;
    Random r = new Random();
    int y = r.nextInt(b);
    if (y < a)
    y += (a - y) + r.nextInt(b - a);
    if (y != a)
    return y;
    else
    return y + 1 + r.nextInt((b - a) - 1);
    }


    البته اعداد پارامتر نباید مساوی باشند. دومی نباید کوچکتر از اولی باشه و تفاضلشون باید بیشتر از 1 باشه وگر نه 1- برمی گردونه.
    این فراموش نشه:
    import java.util.Random;


    آخرین ویرایش به وسیله dasssnj : پنج شنبه 12 تیر 1393 در 23:16 عصر

    Write Once, Run Anywhere

  15. #55
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    اینم رندم ترکیبی از زمان و شئ رندوم:

            public static long rand2(){
    return new Random().nextInt(500)*System.nanoTime();
    }


    Write Once, Run Anywhere

  16. #56

    نقل قول: این هم کد

    با تکه کد زیر میتوانید متن ها را با فونت دلخواه خود در برنامه نشان دهید:
    فونت ها را در پوشه Assets قرار دهید و نام آنها را در مکان مورد نظر تایپ کنید :

    TextView txt = (TextView) parentView.findViewById(R.id.other); 
    Typeface font = Typeface.createFromAsset(getAssets(), "نام فونت");
    txt.setTypeface(font);
    اگر کلاس مورد نظر از fragment اکستندز شده به getActivity() نیاز دارد :

     
    TextView txt = (TextView) parentView.findViewById(R.id.other);
    Typeface font = Typeface.createFromAsset(getActivity().getAssets() , "نام فونت");
    txt.setTypeface(font);



    در آخر یه چند تا سایت برای دانلود فونت های فارسی و فونت های مورد استفاده در برنامه مارکت بازار :
    فونت های مورد استفاده در برنامه بازار


  17. #57
    کاربر دائمی آواتار badname
    تاریخ عضویت
    اردیبهشت 1393
    محل زندگی
    زیر آسمون آبی
    پست
    327

    نقل قول: این هم کد

    شناسی مدل دستگاه و ورژن اندرویدش:

    //Device model
    String PhoneModel = android.os.Build.MODEL;
    //Android version
    String AndroidVersion = android.os.Build.VERSION.RELEASE;



  18. #58
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    پیدا کردن بزرگترین عدد بین هر چندتا عدد که دلتون بخواد !!!!!

    public static int max(int... i){
    int max;
    int c = i[0];
    max=c;
    for (int k = 1; k < i.length; k++){
    if(i[k]>max)
    max=i[k];
    }
    return max;
    }


    طریقه ی استفاده :

            int i = max(2,-5,1000,50,60,600);
    int j = max(1,8,4,54,87,468,354,156,357,68,354,68,34,69);

    Write Once, Run Anywhere

  19. #59
    مدیر بخش آواتار rubiks.kde
    تاریخ عضویت
    آبان 1390
    محل زندگی
    مشهد
    پست
    1,537

    نقل قول: این هم کد

    نقل قول نوشته شده توسط dasssnj مشاهده تاپیک
    پیدا کردن بزرگترین عدد بین هر چندتا عدد که دلتون بخواد !!!!!

    public static int max(int... i){
    int max;
    int c = i[0];
    max=c;
    for (int k = 1; k < i.length; k++){
    if(i[k]>max)
    max=i[k];
    }
    return max;
    }


            int i = max(2,-5,1000,50,60,600);
    int j = max(1,8,4,54,87,468,354,156,357,68,354,68,34,69);
    دوست عزیز این کدها مربوط به طراحی الگوریتم هست و نیازی نیست این جا گفته بشه.تنها کدهای تخصصی اندروید
    طریقه ی استفاده :
    YES I AM Qt


    Code Less
    Create More
    Deploy Everywhere

  20. #60
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    نقل قول نوشته شده توسط rubiks.kde مشاهده تاپیک
    دوست عزیز این کدها مربوط به طراحی الگوریتم هست و نیازی نیست این جا گفته بشه.تنها کدهای تخصصی اندروید
    بله ممنون که تذکر دادید ولی گفتم توی اندروید هم شاید به کار بیاد دیگه

    Write Once, Run Anywhere

  21. #61

    نقل قول: این هم کد

    کد پیدا کردن اندازه استاتوس بار ( نوتیفیکیشن بار )

    همونطور که میدونین یا شاید هم دقت نکردین، استاتوس بار توی اندازه صفحه های مختلف، اندازه های مختلف داره

    مثلا توی اندازه 320*240 اندازه استاتوس بار 20px هست و توی 320*480 برابر 25px و توی 480*720 برابر 38px و ...

    با کد زیر به راحتی اندازه رو به دست بیارید ( مورد استفاده در طراحی طبق اندازه )

    public int getStatusBarHeight() {      int result = 0;
    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
    result = getResources().getDimensionPixelSize(resourceId);
    }
    return result;
    }

  22. #62
    مدیر بخش آواتار dasssnj
    تاریخ عضویت
    مرداد 1391
    محل زندگی
    Esfahan
    پست
    1,022

    نقل قول: این هم کد

    این هم کد تبدیل string به int با الگوریتمی متفاوت از Integer.parseInt .

        public static int strToint(String e) throws NumberFormatException {
    if (e == null || e.length() < 1 || e.equals("")) //string moshkel dare
    throw new NumberFormatException("String : " + e + " is corrupt !");

    char[] ch = e.toCharArray();
    boolean negative = false; //manfi
    int len = ch.length; // toole adad
    int[] i = new int[len]; //araye adad
    short j, k; // adad halghe ha
    int result = 0; //javab
    if (ch[0] == '-') { //manfi
    if (e.length() == 1)
    throw new NumberFormatException("String : " + e + " is corrupt !");

    negative = true; // manfi mishe
    ch = e.substring(1).toCharArray();
    len = ch.length;
    } else if (ch[0] == '+') { //mosbat
    if (e.length() == 1)
    throw new NumberFormatException("String : " + e + " is corrupt !");
    ch = e.substring(1).toCharArray();
    len = ch.length;
    }

    for (j = 0; j < len; j++) {
    if (ch[j] < '0' || ch[j] > '9') // bayad beine 0 ta 9 bashe
    throw new NumberFormatException("String : " + e + " Not a Number !");
    i[j] = ch[j] - 48; // az char ke adad bashe 48 ta kam koni mishe int
    for (k = 0; k < len - (j + 1); k++)
    i[j] *= 10; //sefr ha ra mizaram ba zarb dar 10

    result += i[j]; // hala jam mikonam
    if (result < 0) //aslan nabayad manfi bashe
    {
    if (result == -2147483648 && negative) {//No problem (-|0)
    // irad az man nist . system manfi bar migardoone . baray hamin in shart lazeme
    } else //adad bozorg tar az int
    {
    throw new NumberFormatException("Number : " + e + " is out of range for int! ");
    }
    }
    }
    return negative ? -result : result; // manfi bashe ya mosbat
    }
    آخرین ویرایش به وسیله dasssnj : پنج شنبه 05 تیر 1393 در 20:08 عصر

    Write Once, Run Anywhere

  23. #63

    نقل قول: این هم کد

    کد حالت تایپ کردن تکست در textView


    این تابع رو توی اکتیویتی اضافه کنین، تکست خودتون رو توی متغیر matn قرار بدید

        String matn = "اینجا متن مورد نظر رو قرار بدید"; 
    int cnt = 0;
    private Handler handler = new Handler();

    private Runnable removeTxtPoint = new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    if(cnt <= matn.length()){
    textView.setText(matn.substring(0, cnt));
    cnt++;
    }else{
    handler.removeCallbacks(removeTxtPoint);
    }
    handler.postDelayed(this, 5); // میتونین این عدد رو تغییر بدید تا سرعت کم یا زیاد بشه
    }
    };


    بعدش توی متد onStart اکتیویتی تون، این کد رو بنویسید

    removeTxtPoint.run();

  24. #64
    کاربر دائمی
    تاریخ عضویت
    اسفند 1388
    محل زندگی
    Tehran
    پست
    453

    نقل قول: این هم کد

    سلام

    میشه درباره این کد توضیح بدین؟

    try{
    PackageManager pm = getPackageManager();
    ApplicationInfo ai = pm.getApplicationInfo(getPackageName(), 0);
    File srcFile = new File(ai.publicSourceDir);
    Intent share = new Intent();
    share.setAction(Intent.ACTION_SEND);
    share.setType("application/vnd.android.package-archive");
    share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(srcFile));
    startActivity(Intent.createChooser(share, "MyApp"));
    } catch (Exception e) {
    Log.e("ShareApp", e.getMessage());
    }

  25. #65
    کاربر دائمی آواتار saeed_g21
    تاریخ عضویت
    مرداد 1388
    محل زندگی
    تبریز
    پست
    1,078

    نقل قول: این هم کد

    بازم که خیلی وقته بروز نشده که

    مبدل تاریخ شمسی به میلادی

    خودم نوشتم تست کردم جواب داده شما هم قبل استفاده تست کنید بهتره
    قابل شما دوستان رو نداره

    public class MiladiDate {	public String todayMiladi(int y,int m,int d) {

    String year = ""+y;
    String month = ""+m;
    String day = ""+d;
    int Y = Integer.valueOf(year);
    int M = Integer.valueOf(month);
    int D = Integer.valueOf(day);
    return Shamsi(Y, M, D);
    }

    public String Shamsi(int Y, int M, int D)
    {
    int gDay,gMonth,gYear;
    switch(M) {
    case 1:
    if(D <= 11){
    M = 3;
    D = D + 20;
    }else{
    M = 4;
    D = D - 11;
    }
    break;
    case 2:
    if(D <= 10){
    M = 4;
    D = D + 20;
    }else{
    M = 5;
    D = D -10;
    }
    break;
    case 3:
    if(D <= 10){
    M = 5;
    D = D + 21;
    }else{
    M = 6;
    D = D - 10;
    }
    break;
    case 4:
    if(D <= 9 ){
    M = 6;
    D = D + 21;
    }else{
    M = 7;
    D = D - 9;
    }
    break;
    case 5:
    if( D <= 9){
    M = 7;
    D = D + 22;
    }else{
    M = 8;
    D = D - 9;
    }
    break;
    case 6:
    if(D <= 9){
    M = 8;
    D = D + 22;
    }else{
    M=9;
    D = D - 9;
    }
    break;
    case 7:
    if(D <= 8){
    M = 9;
    D = D + 22;
    }else{
    M = 10;
    D = D - 8;
    }
    break;
    case 8:
    if(D <= 9){
    M = 10;
    D = D + 22;
    }else{
    M = 11;
    D = D - 9;
    }
    break;
    case 9:
    if(D <= 9){
    M = 11;
    D = D + 21;
    }else{
    M = 12;
    D = D - 9;
    }
    break;
    case 10:
    if(D <= 10){
    M = 12;
    D = D + 21;
    }else{
    M = 1;
    D = D - 10;
    }
    break;
    case 11:
    if(D <= 11){
    M = 1;
    D = D + 20;
    }else{
    M = 2;
    D = D - 11;
    }
    break;
    case 12:
    if(D <= 9 ){
    M = 2;
    D = D + 19 ;
    }else{
    M = 3;
    D = D - 9;
    }
    break;
    }

    gDay = D;
    gMonth = M;
    gYear = Y+621+ (8-gMonth)/6;
    return ""+gDay + "/"+gMonth +"/"+gYear;
    }





    نحوه استفاده :

    1) فایلی (Class) که ایجاد میکنید حتما اسمش MiladiDate باشه
    2)

    MiladiDate MDate = new MiladiDate();
    MDate.todayMiladi(1393, 04, 27);


    توجه مهم : بایستی تاریخ شمسی رو بصورتی که در نمونه وارد شده وارد کنید تا به تاریخ میلادی تبدیل شود

  26. #66
    کاربر دائمی آواتار abbasalim
    تاریخ عضویت
    تیر 1391
    محل زندگی
    یزد ـ‌ اردکان
    پست
    1,039

    نقل قول: این هم کد

    saeed_g21 اگه برعکسش رو هم داری بزار که کامل بشه

  27. #67
    کاربر دائمی آواتار saeed_g21
    تاریخ عضویت
    مرداد 1388
    محل زندگی
    تبریز
    پست
    1,078

    نقل قول: این هم کد

    نقل قول نوشته شده توسط abbasalim مشاهده تاپیک
    saeed_g21 اگه برعکسش رو هم داری بزار که کامل بشه
    نه ننوشتم براش ولی بزودی به یاری خدا حلش میکنم میدم

  28. #68

    نقل قول: این هم کد

    به دست آوردن اسم تمامی عکس های داخل پوشه drawable

    و طریقه تبدیل اسم عکس به آیدی

    --------------

    این کدها توی پروژه جدیدم استفاده شد که دیدم میتونه مفید واقع بشه

    اگر خواستین لیستی از نام عکس های داخل پوشه drawable بگیرید به صورت زیر عمل کنید و نام ها رو داخل لیست picsList بریزید

                Field[] drawables = R.drawable.class.getFields();
    ArrayList<String> picsList = new ArrayList<String>();
    for (Field f : drawables) {
    try {

    picsList.add(f.getName());

    } catch (Exception e) {
    e.printStackTrace();
    }

    }


    این کد تمام عکس رو میگیره، حالا اگر خواستید یک سری عکس مشخص رو بگیرید باید چکار کنید ؟؟؟


    یک راه حل اینه که توی اسم عکس هاتون مشخص کنید، مثلا اسم آیکون ها رو اینطوری تغییر بدید icon_image_name

    بعد توی کد بالا چک میکنید که اگر اسم عکس شامل _icon بود اون اسم رو داخل لیست قرار بده

                        if(f.getName().toString().indexOf("icon_") > -1){
    picsList.add(f.getName());
    }


    بعد این لیست رو میتونید بفرستید به یک آداپتر، توی لیست ویو یا هرجای دیگه نمایشش بدید

    و اما اینکه چطور با استفاده از اسم عکس ها، به آیدی اون دسترسی پیدا کنید

                int id = context.getResources().getIdentifier("your_image_n  ame", "drawable", getPackageName());
    imageView.setImageResource(id);

  29. #69

    نقل قول: این هم کد

    فعال و غیر فعال کردن نوتیفیکیشن با toggle button
    ویژگی ها : اگه toggle button روشن کنی notifacition میاد و با اجبار هم میمونه اون بالا واگه خاموش کنی notification حذف میشه

    import android.os.Bundle;

    import android.app.Activity;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.support.v4.app.NotificationCompat;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ToggleButton;


    public class Notificatio extends Activity {
    //private static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    protected static final int NOTIFICATION_ID = 0;




    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("نوار اعلان");
    setContentView(R.layout.notificition);


    NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(this);


    mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


    /* notificationID allows you to update the notification later on. */
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    /** تعریف تنظیمات برای نوتیفیکیشن ما */
    /** تعریف تنظیمات برای نوتیفیکیشن ما */
    int icon = R.drawable.ic_launcher;
    /**آدرس آیکون موردنظر جهت نمایش در استاتوس بار*/
    CharSequence tickerText = "نوتیفیکیشن فعال شد";
    long when = System.currentTimeMillis();
    Context context = getApplicationContext();
    CharSequence contentTitle = "TagsUpLikes";
    CharSequence contentText = "برای انتخاب تگ ها اینجا کلیک کنید";
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);


    /** مقداردهی اولیه Notificationبا استفاده از تنظیمات بالا */
    final Notification notification = new Notification(icon, tickerText, when);
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);


    /** بازیابی مرجع از NotificationManager*/
    String ns = Context.NOTIFICATION_SERVICE;
    final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);


    /**final ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButton1);
    tb.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
    if(tb.isChecked()){
    mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
    else{
    cancelNotification();

    }
    }
    });
    *\

    ///** Listener برای کلیک */
    Button statusbarnotify = (Button) findViewById(R.id.Button1);
    statusbarnotify.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    mNotificationManager.notify(NOTIFICATION_ID, notification);
    }

    });
    Button cancelnorify = (Button) findViewById(R.id.button2);
    cancelnorify.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
    cancelNotification();

    }
    });
    }

    protected void cancelNotification() {
    Log.i("Cancel", "notification");
    mNotificationManager.cancel(NOTIFICATION_ID);






    }


    }


  30. #70
    کاربر دائمی آواتار ho3ein.3ven
    تاریخ عضویت
    آذر 1390
    محل زندگی
    بوشهر
    پست
    1,185

    نقل قول: این هم کد

    نقل قول نوشته شده توسط moralschool مشاهده تاپیک
    اگه بخوای از یه پوشه مثلا از raw فراخوانی کنی میتونی این کد رو در یه دکمه و در on creat قرار بدی

    saveas1(RingtoneManager.TYPE_RINGTONE);

    و کد زیر رو هم بعد از oncreat یعنی خارج از اون ، قرار بدی :


    public boolean saveas1(int type) {
    byte[] buffer = null;
    InputStream fIn = getBaseContext().getResources().openRawResource(
    R.raw.zang1);
    int size = 0;

    try {
    size = fIn.available();
    buffer = new byte[size];
    fIn.read(buffer);
    fIn.close();
    } catch (IOException e) {
    return false;
    }

    String path = Environment.getExternalStorageDirectory().getPath( )
    + "/media/audio/ringtones/";

    String filename = "zang1.mp3";

    boolean exists = (new File(path)).exists();
    if (!exists) {
    new File(path).mkdirs();
    }

    FileOutputStream save;
    try {
    save = new FileOutputStream(path + filename);
    save.write(buffer);
    save.flush();
    save.close();
    } catch (FileNotFoundException e) {
    return false;
    } catch (IOException e) {
    return false;
    }

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
    Uri.parse("file://" + path + filename)));

    File k = new File(path, filename);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE, filename);
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");

    // This method allows to change Notification and Alarm tone also. Just
    // pass corresponding type as parameter
    if (RingtoneManager.TYPE_RINGTONE == type) {
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
    } else if (RingtoneManager.TYPE_NOTIFICATION == type) {
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
    } else if (RingtoneManager.TYPE_ALARM == type) {
    values.put(MediaStore.Audio.Media.IS_ALARM, true);
    }

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
    .getAbsolutePath());
    Uri newUri = Zang.this.getContentResolver().insert(uri, values);
    RingtoneManager.setActualDefaultRingtoneUri(Zang.t his, type,
    newUri);

    // Insert it into the database
    this.getContentResolver()
    .insert(MediaStore.Audio.Media.getContentUriForPat h(k
    .getAbsolutePath()), values);

    return true;
    }

    حالا بعضی جاها توی این پست سیستم این انجمن خودش فاصله انداخته و نمیشه برداشتشون ! و توی ایکلیپس خطا میده و معلومن ! اونا رو فاصله هاشونو حذف کنید درست میشه
    کد تست شده و بدرستی کار میکنه

    سلام

    برای این کد دسترسی های زیر باید اضافه بشه :

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ORAGE"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>

  31. #71

    نقل قول: این هم کد

    چرخش تصویر در محور مرکزی خودش :

    باید کلاسی بسازید که از ImageView مشتق شده باشد:

    public class RotateImageView extends ImageView {
    private static Animation mRotation;
    public boolean isAnimating = false;

    public RotateImageView(Context context) {
    super(context);
    Init(null);
    }

    public RotateImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Init(attrs);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public RotateImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    Init(attrs);
    }

    private void Init(AttributeSet attrs) {
    startAnimation();
    }

    public void startAnimation() {
    if(!isAnimating){
    if (mRotation == null) {
    mRotation = AnimationUtils.loadAnimation(getContext(), R.anim.rotate);
    mRotation.setRepeatCount(Animation.INFINITE);
    }
    this.startAnimation(mRotation);
    isAnimating = true;
    }

    }

    public void stopAnimation() {
    if (isAnimating){
    mRotation.cancel();
    isAnimating = false;
    }
    }

    @Override
    public void setVisibility(int visibility) {
    if (visibility == GONE || visibility == INVISIBLE) {
    this.clearAnimation();
    } else if (visibility == VISIBLE) {
    this.startAnimation(mRotation);
    }
    super.setVisibility(visibility);
    }
    }


    سپس در پوشه anim یک فایل xml به نام rotate بسازید:



    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="5000"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:startOffset="0"
    android:toDegrees="360" />




    سپس در فایل xml :

    <yourpackage.RotateImageView
    android:id="@+id/yourid"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/yourimage"
    />


    سپس هرجا خواستید :

    private static RotateImageView rotateimageview

    rotateimageview = new RotateImageView(getActivity());

    rotateimageview.stopAnimation();

    or

    rotateimageview.startAnimation();


    نکته: در Fragmentها باید از getActivity استفاده کنید و در Activityها از this یا getApplicationContext .
    آخرین ویرایش به وسیله smemamian : دوشنبه 20 مرداد 1393 در 19:43 عصر

  32. #72

    نقل قول: این هم کد

    کد اشتراک گذاری عکس:

    Bitmap bitmap;
    OutputStream output;

    bitmap=BitmapFactory.decodeResource(getResources() ,
    com.example.ties.R.drawable.checkerboard_sare);

    File filepath=Environment.getExternalStorageDirectory() ;

    File dir=new File(filepath.getAbsolutePath()+"/Share_checkerboard/");
    dir.mkdir();

    final File file=new File(dir, "checkerboard_share");



    ImageView iv=(ImageView) findViewById(com.example.ties.R.id.checkerboard_sh are);
    iv.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
    // TODO Auto-generated method stub
    Bitmap bitmap;
    OutputStream output;

    // Retrieve the image from the res folder
    bitmap = BitmapFactory.decodeResource(getResources(),
    com.example.ties.R.drawable.checkerboard_sare);

    // Find the SD Card path
    File filepath = Environment.getExternalStorageDirectory();

    // Create a new folder AndroidBegin in SD Card
    File dir = new File(filepath.getAbsolutePath() + "/Share Image/");
    dir.mkdirs();

    // Create a name for the saved image
    File file = new File(dir, "checkerboard.png");

    try {

    // Share Intent
    Intent share = new Intent(Intent.ACTION_SEND);

    // Type of file to share
    share.setType("image/jpeg");

    output = new FileOutputStream(file);

    // Compress into png format image from 0% - 100%
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
    output.flush();
    output.close();

    // Locate the image to Share
    Uri uri = Uri.fromFile(file);

    // Pass the image into an Intnet
    share.putExtra(Intent.EXTRA_STREAM, uri);

    // Show the social share chooser list
    startActivity(Intent.createChooser(share, "Share Image"));

    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    return;
    }
    });
    };



  33. #73
    کاربر دائمی آواتار abbasalim
    تاریخ عضویت
    تیر 1391
    محل زندگی
    یزد ـ‌ اردکان
    پست
    1,039

    نقل قول: این هم کد

    تبدیل تاریخ میلادی قمری و شمسی به هم دیگه


    package ir.esfandune.extera;

    import java.util.Calendar;
    import java.util.GregorianCalendar;


    /**
    * Title: Calender Conversion class
    * Description: Convert Iranian (Jalali), Julian, and Gregorian dates to
    * each other
    * Public Methods Summary:
    * -----------------------
    * JavaSource_Calendar();
    * JavaSource_Calendar(int year, int month, int day);
    * int getIranianYear();
    * int getIranianMonth();
    * int getIranianDay();
    * int getGregorianYear();
    * int getGregorianMonth();
    * int getGregorianDay();
    * int getJulianYear();
    * int getJulianMonth();
    * int getJulianDay();
    * String getIranianDate();
    * String getGregorianDate();
    * String getJulianDate();
    * String getWeekDayStr();
    * String toString();
    * int getDayOfWeek();
    * void nextDay();
    * void nextDay(int days);
    * void previousDay();
    * void previousDay(int days);
    * void setIranianDate(int year, int month, int day);
    * void setGregorianDate(int year, int month, int day);
    * void setJulianDate(int year, int month, int day);
    */
    public class CalendarTool {

    /**
    * JavaSource_Calendar:
    * The default constructor uses the current Gregorian date to initialize the
    * other private memebers of the class (Iranian and Julian dates).
    */
    public CalendarTool()
    {
    Calendar calendar = new GregorianCalendar();
    setGregorianDate(calendar.get(Calendar.YEAR),
    calendar.get(Calendar.MONTH)+1,
    calendar.get(Calendar.DAY_OF_MONTH));
    }

    /**
    * JavaSource_Calendar:
    * This constructor receives a Gregorian date and initializes the other private
    * members of the class accordingly.
    * @param year int
    * @param month int
    * @param day int
    */
    public CalendarTool(int year, int month, int day)
    {
    setGregorianDate(year,month,day);
    }

    /**
    * getIranianYear:
    * Returns the 'year' part of the Iranian date.
    * @return int
    */
    public int getIranianYear() {
    return irYear;
    }

    /**
    * getIranianMonth:
    * Returns the 'month' part of the Iranian date.
    * @return int
    */
    public int getIranianMonth() {
    return irMonth;
    }

    /**
    * getIranianDay:
    * Returns the 'day' part of the Iranian date.
    * @return int
    */
    public int getIranianDay() {
    return irDay;
    }

    /**
    * getGregorianYear:
    * Returns the 'year' part of the Gregorian date.
    * @return int
    */
    public int getGregorianYear() {
    return gYear;
    }

    /**
    * getGregorianMonth:
    * Returns the 'month' part of the Gregorian date.
    * @return int
    */
    public int getGregorianMonth() {
    return gMonth;
    }

    /**
    * getGregorianDay:
    * Returns the 'day' part of the Gregorian date.
    * @return int
    */
    public int getGregorianDay() {
    return gDay;
    }

    /**
    * getJulianYear:
    * Returns the 'year' part of the Julian date.
    * @return int
    */
    public int getJulianYear() {
    return juYear;
    }

    /**
    * getJulianMonth:
    * Returns the 'month' part of the Julian date.
    * @return int
    */
    public int getJulianMonth() {
    return juMonth;
    }

    /**
    * getJulianDay()
    * Returns the 'day' part of the Julian date.
    * @return int
    */
    public int getJulianDay() {
    return juDay;
    }

    /**
    * getIranianDate:
    * Returns a string version of Iranian date
    * @return String
    */
    public String getIranianDate()
    {
    return (irYear+"/"+irMonth+"/"+irDay);
    }

    /**
    * getGregorianDate:
    * Returns a string version of Gregorian date
    * @return String
    */
    public String getGregorianDate()
    {
    return (gYear+"/"+gMonth+"/"+gDay);
    }

    /**
    * getJulianDate:
    * Returns a string version of Julian date
    * @return String
    */
    public String getJulianDate()
    {
    return (juYear+"/"+juMonth+"/"+juDay);
    }

    /**
    * getWeekDayStr:
    * Returns the week day name.
    * @return String
    */
    public String getWeekDayStr()
    {
    String weekDayStr[]={
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"};
    return (weekDayStr[getDayOfWeek()]);
    }

    /**
    * toString:
    * Overrides the default toString() method to return all dates.
    * @return String
    */
    public String toString()
    {
    return (getWeekDayStr()+
    ", Gregorian:["+getGregorianDate()+
    "], Julian:["+getJulianDate()+
    "], Iranian:["+getIranianDate()+"]");
    }


    /**
    * getDayOfWeek:
    * Returns the week day number. Monday=0..Sunday=6;
    * @return int
    */
    public int getDayOfWeek()
    {
    return (JDN % 7);
    }

    /**
    * nextDay:
    * Go to next julian day number (JDN) and adjusts the other dates.
    */
    public void nextDay()
    {
    JDN++;
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }
    /**
    * nextDay:
    * Overload the nextDay() method to accept the number of days to go ahead and
    * adjusts the other dates accordingly.
    * @param days int
    */
    public void nextDay(int days)
    {
    JDN+=days;
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * previousDay:
    * Go to previous julian day number (JDN) and adjusts the otehr dates.
    */
    public void previousDay()
    {
    JDN--;
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * previousDay:
    * Overload the previousDay() method to accept the number of days to go backward
    * and adjusts the other dates accordingly.
    * @param days int
    */
    public void previousDay(int days)
    {
    JDN-=days;
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * setIranianDate:
    * Sets the date according to the Iranian calendar and adjusts the other dates.
    * @param year int
    * @param month int
    * @param day int
    */
    public void setIranianDate(int year, int month, int day)
    {
    irYear =year;
    irMonth = month;
    irDay = day;
    JDN = IranianDateToJDN();
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * setGregorianDate:
    * Sets the date according to the Gregorian calendar and adjusts the other dates.
    * @param year int
    * @param month int
    * @param day int
    */
    public void setGregorianDate(int year, int month, int day)
    {
    gYear = year;
    gMonth = month;
    gDay = day;
    JDN = gregorianDateToJDN(year,month,day);
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * setJulianDate:
    * Sets the date according to the Julian calendar and adjusts the other dates.
    * @param year int
    * @param month int
    * @param day int
    */
    public void setJulianDate(int year, int month, int day)
    {
    juYear = year;
    juMonth = month;
    juDay = day;
    JDN = julianDateToJDN(year,month,day);
    JDNToIranian();
    JDNToJulian();
    JDNToGregorian();
    }

    /**
    * IranianCalendar:
    * This method determines if the Iranian (Jalali) year is leap (366-day long)
    * or is the common year (365 days), and finds the day in March (Gregorian
    * Calendar)of the first day of the Iranian year ('irYear').Iranian year (irYear)
    * ranges from (-61 to 3177).This method will set the following private data
    * members as follows:
    * leap: Number of years since the last leap year (0 to 4)
    * Gy: Gregorian year of the begining of Iranian year
    * march: The March day of Farvardin the 1st (first day of jaYear)
    */
    private void IranianCalendar()
    {
    // Iranian years starting the 33-year rule
    int Breaks[]=
    {-61, 9, 38, 199, 426, 686, 756, 818,1111,1181,
    1210,1635,2060,2097,2192,2262,2324,2394,2456,3178} ;
    int jm,N,leapJ,leapG,jp,j,jump;
    gYear = irYear + 621;
    leapJ = -14;
    jp = Breaks[0];
    // Find the limiting years for the Iranian year 'irYear'
    j=1;
    do{
    jm=Breaks[j];
    jump = jm-jp;
    if (irYear >= jm)
    {
    leapJ += (jump / 33 * 8 + (jump % 33) / 4);
    jp = jm;
    }
    j++;
    } while ((j<20) && (irYear >= jm));
    N = irYear - jp;
    // Find the number of leap years from AD 621 to the begining of the current
    // Iranian year in the Iranian (Jalali) calendar
    leapJ += (N/33 * 8 + ((N % 33) +3)/4);
    if ( ((jump % 33) == 4 ) && ((jump-N)==4))
    leapJ++;
    // And the same in the Gregorian date of Farvardin the first
    leapG = gYear/4 - ((gYear /100 + 1) * 3 / 4) - 150;
    march = 20 + leapJ - leapG;
    // Find how many years have passed since the last leap year
    if ( (jump - N) < 6 )
    N = N - jump + ((jump + 4)/33 * 33);
    leap = (((N+1) % 33)-1) % 4;
    if (leap == -1)
    leap = 4;
    }


    /**
    * IsLeap:
    * This method determines if the Iranian (Jalali) year is leap (366-day long)
    * or is the common year (365 days), and finds the day in March (Gregorian
    * Calendar)of the first day of the Iranian year ('irYear').Iranian year (irYear)
    * ranges from (-61 to 3177).This method will set the following private data
    * members as follows:
    * leap: Number of years since the last leap year (0 to 4)
    * Gy: Gregorian year of the begining of Iranian year
    * march: The March day of Farvardin the 1st (first day of jaYear)
    */
    public boolean IsLeap(int irYear1)
    {
    // Iranian years starting the 33-year rule
    int Breaks[]=
    {-61, 9, 38, 199, 426, 686, 756, 818,1111,1181,
    1210,1635,2060,2097,2192,2262,2324,2394,2456,3178} ;
    int jm,N,leapJ,leapG,jp,j,jump;
    gYear = irYear1 + 621;
    leapJ = -14;
    jp = Breaks[0];
    // Find the limiting years for the Iranian year 'irYear'
    j=1;
    do{
    jm=Breaks[j];
    jump = jm-jp;
    if (irYear1 >= jm)
    {
    leapJ += (jump / 33 * 8 + (jump % 33) / 4);
    jp = jm;
    }
    j++;
    } while ((j<20) && (irYear1 >= jm));
    N = irYear1 - jp;
    // Find the number of leap years from AD 621 to the begining of the current
    // Iranian year in the Iranian (Jalali) calendar
    leapJ += (N/33 * 8 + ((N % 33) +3)/4);
    if ( ((jump % 33) == 4 ) && ((jump-N)==4))
    leapJ++;
    // And the same in the Gregorian date of Farvardin the first
    leapG = gYear/4 - ((gYear /100 + 1) * 3 / 4) - 150;
    march = 20 + leapJ - leapG;
    // Find how many years have passed since the last leap year
    if ( (jump - N) < 6 )
    N = N - jump + ((jump + 4)/33 * 33);
    leap = (((N+1) % 33)-1) % 4;
    if (leap == -1)
    leap = 4;
    if (leap==4 || leap==0)
    return true;
    else
    return false;

    }



    /**
    * IranianDateToJDN:
    * Converts a date of the Iranian calendar to the Julian Day Number. It first
    * invokes the 'IranianCalender' private method to convert the Iranian date to
    * Gregorian date and then returns the Julian Day Number based on the Gregorian
    * date. The Iranian date is obtained from 'irYear'(1-3100),'irMonth'(1-12) and
    * 'irDay'(1-29/31).
    * @return long (Julian Day Number)
    */
    private int IranianDateToJDN()
    {
    IranianCalendar();
    return (gregorianDateToJDN(gYear,3,march)+ (irMonth-1) * 31 - irMonth/7 * (irMonth-7) + irDay -1);
    }

    /**
    * JDNToIranian:
    * Converts the current value of 'JDN' Julian Day Number to a date in the
    * Iranian calendar. The caller should make sure that the current value of
    * 'JDN' is set correctly. This method first converts the JDN to Gregorian
    * calendar and then to Iranian calendar.
    */
    private void JDNToIranian()
    {
    JDNToGregorian();
    irYear = gYear - 621;
    IranianCalendar(); // This invocation will update 'leap' and 'march'
    int JDN1F = gregorianDateToJDN(gYear,3,march);
    int k = JDN - JDN1F;
    if (k >= 0)
    {
    if (k <= 185)
    {
    irMonth = 1 + k/31;
    irDay = (k % 31) + 1;
    return;
    }
    else
    k -= 186;
    }
    else
    {
    irYear--;
    k += 179;
    if (leap == 1)
    k++;
    }
    irMonth = 7 + k/30;
    irDay = (k % 30) + 1;
    }


    /**
    * julianDateToJDN:
    * Calculates the julian day number (JDN) from Julian calendar dates. This
    * integer number corresponds to the noon of the date (i.e. 12 hours of
    * Universal Time). This method was tested to be good (valid) since 1 March,
    * -100100 (of both calendars) up to a few millions (10^6) years into the
    * future. The algorithm is based on D.A.Hatcher, Q.Jl.R.Astron.Soc. 25(1984),
    * 53-55 slightly modified by K.M. Borkowski, Post.Astron. 25(1987), 275-279.
    * @param year int
    * @param month int
    * @param day int
    * @return int
    */
    private int julianDateToJDN(int year, int month, int day)
    {
    return (year + (month - 8) / 6 + 100100) * 1461/4 + (153 * ((month+9) % 12) + 2)/5 + day - 34840408;
    }

    /**
    * JDNToJulian:
    * Calculates Julian calendar dates from the julian day number (JDN) for the
    * period since JDN=-34839655 (i.e. the year -100100 of both calendars) to
    * some millions (10^6) years ahead of the present. The algorithm is based on
    * D.A. Hatcher, Q.Jl.R.Astron.Soc. 25(1984), 53-55 slightly modified by K.M.
    * Borkowski, Post.Astron. 25(1987), 275-279).
    */
    private void JDNToJulian()
    {
    int j= 4 * JDN + 139361631;
    int i= ((j % 1461)/4) * 5 + 308;
    juDay = (i % 153) / 5 + 1;
    juMonth = ((i/153) % 12) + 1;
    juYear = j/1461 - 100100 + (8-juMonth)/6;
    }

    /**
    * gergorianDateToJDN:
    * Calculates the julian day number (JDN) from Gregorian calendar dates. This
    * integer number corresponds to the noon of the date (i.e. 12 hours of
    * Universal Time). This method was tested to be good (valid) since 1 March,
    * -100100 (of both calendars) up to a few millions (10^6) years into the
    * future. The algorithm is based on D.A.Hatcher, Q.Jl.R.Astron.Soc. 25(1984),
    * 53-55 slightly modified by K.M. Borkowski, Post.Astron. 25(1987), 275-279.
    * @param year int
    * @param month int
    * @param day int
    * @return int
    */
    private int gregorianDateToJDN(int year, int month, int day)
    {
    int jdn = (year + (month - 8) / 6 + 100100) * 1461/4 + (153 * ((month+9) % 12) + 2)/5 + day - 34840408;
    jdn = jdn - (year + 100100+(month-8)/6)/100*3/4+752;
    return (jdn);
    }
    /**
    * JDNToGregorian:
    * Calculates Gregorian calendar dates from the julian day number (JDN) for
    * the period since JDN=-34839655 (i.e. the year -100100 of both calendars) to
    * some millions (10^6) years ahead of the present. The algorithm is based on
    * D.A. Hatcher, Q.Jl.R.Astron.Soc. 25(1984), 53-55 slightly modified by K.M.
    * Borkowski, Post.Astron. 25(1987), 275-279).
    */
    private void JDNToGregorian()
    {
    int j= 4 * JDN + 139361631;
    j = j + (((((4* JDN +183187720)/146097)*3)/4)*4-3908);
    int i= ((j % 1461)/4) * 5 + 308;
    gDay = (i % 153) / 5 + 1;
    gMonth = ((i/153) % 12) + 1;
    gYear = j/1461 - 100100 + (8-gMonth)/6;
    }


    private int irYear; // Year part of a Iranian date
    private int irMonth; // Month part of a Iranian date
    private int irDay; // Day part of a Iranian date
    private int gYear; // Year part of a Gregorian date
    private int gMonth; // Month part of a Gregorian date
    private int gDay; // Day part of a Gregorian date
    private int juYear; // Year part of a Julian date
    private int juMonth; // Month part of a Julian date
    private int juDay; // Day part of a Julian date
    private int leap; // Number of years since the last leap year (0 to 4)
    private int JDN; // Julian Day Number
    private int march; // The march day of Farvardin the first (First day of jaYear)
    } // End of Class 'JavaSource_Calendar



  34. #74

    نقل قول: این هم کد

    گرفتن کد USSD :
    Intent call=new Intent(Intent.ACTION_CALL);
    call.setData(Uri.parse("tel:*140*1"+Uri.encode("#" )));
    startActivity(call);

  35. #75

    نقل قول: این هم کد

    استفاده از 2 فونت الی بیشتر در یک TextView :


    Capture.JPG

    دریافت

    توجه داشته باشید که فونت دلخواه رو در قسمت fonts بذارید.

  36. #76

    نقل قول: این هم کد

    سلام
    میشه بیشتر توضیح بدین

  37. #77
    کاربر دائمی آواتار saeedgholami
    تاریخ عضویت
    بهمن 1391
    محل زندگی
    فارس
    سن
    11
    پست
    231

    نقل قول: این هم کد

    سلام دوستان زیاد پرسیدن که چجوری میشه به اکشن بار دکمه اضافه کرد من اموزشش رو گذاشتم فقط نمیدونم این اموزش تو سایت وجود داره یا نه؟؟

    ابتدا باید ی فایل xml ایجاد کنید:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/action_share"
    android:icon="@drawable/share"
    android:title="@string/app_name"

    android:showAsAction="ifRoom"/>

    <item android:id="@+id/action_save"
    android:icon="@drawable/save"
    android:title="@string/app_name"

    android:showAsAction="ifRoom"/>

    </menu>


    بعد تو اکتیویتی این کد را وارد میکنیم


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return super.onCreateOptionsMenu(menu);
    }


    و برای اینه کاربر اگر انتخاب کرد کاری انجام دهد این قطعه کد را اضافه می کنیم


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_share:
    //این کار را انجام بده
    break;

    case R.id.action_save:
    //این کار را انجام بده
    break;
    default:
    return super.onOptionsItemSelected(item);
    }
    }


    امیدوارم اموزش واسه دوستان مفید باشه

  38. #78

    نقل قول: این هم کد

    اسکرول بالا و پایین اتوماتیک

    همانند بازار.

    این تابع در ابتدا یک بار فراخوانی کنید سپس با SP دیگه نذارید فراخوانی شود:

    private void motionRightMenuJustOnce(){

    new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    mMenuDrawer.openMenu();
    }
    }, 800);


    mList.postDelayed(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    mList.setSelection(mAdapter.getCount() - 1);
    }
    }, 1300);

    mList.postDelayed(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    mList.setSelection(0);
    }
    }, 1500);

    new Handler().postDelayed(new Runnable() {

    @Override
    public void run() {
    // TODO Auto-generated method stub
    mMenuDrawer.closeMenu(true);
    }
    }, 2000);
    }

  39. #79
    کاربر دائمی آواتار ho3ein.3ven
    تاریخ عضویت
    آذر 1390
    محل زندگی
    بوشهر
    پست
    1,185

    نقل قول: این هم کد

    اضافه کردن شماره جدید به contacts

    فراخوانی :

    Insert2Contacts(this, "hossein","09375552233");


    توابع :

        public static void Insert2Contacts(Context ctx, String nameSurname,
    String telephone) {
    if (!isTheNumberExistsinContacts(ctx, telephone)) {
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    int rawContactInsertIndex = ops.size();

    ops.add(ContentProviderOperation.newInsert(RawCont acts.CONTENT_URI)
    .withValue(RawContacts.ACCOUNT_TYPE, null)
    .withValue(RawContacts.ACCOUNT_NAME, null).build());
    ops.add(ContentProviderOperation
    .newInsert(ContactsContract.Data.CONTENT_URI)
    .withValueBackReference(
    ContactsContract.Data.RAW_CONTACT_ID,
    rawContactInsertIndex)
    .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
    .withValue(Phone.NUMBER, telephone).build());
    ops.add(ContentProviderOperation
    .newInsert(Data.CONTENT_URI)
    .withValueBackReference(Data.RAW_CONTACT_ID,
    rawContactInsertIndex)
    .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
    .withValue(StructuredName.DISPLAY_NAME, nameSurname)
    .build());
    try {
    ContentProviderResult[] res = ctx.getContentResolver()
    .applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (Exception e) {

    Log.d("d", e.getMessage());
    }
    }
    }

    public static boolean isTheNumberExistsinContacts(Context ctx,
    String phoneNumber) {
    Cursor cur = null;
    ContentResolver cr = null;

    try {
    cr = ctx.getContentResolver();

    } catch (Exception ex) {
    Log.d("f", ex.getMessage());
    }

    try {
    cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null,
    null, null);
    } catch (Exception ex) {
    Log.i("f", ex.getMessage());
    }

    try {
    if (cur.getCount() > 0) {
    while (cur.moveToNext()) {
    String id = cur.getString(cur
    .getColumnIndex(ContactsContract.Contacts._ID));
    String name = cur
    .getString(cur
    .getColumnIndex(ContactsContract.Contacts.DISPLAY_ NAME));
    // Log.i("Names", name);
    if (Integer
    .parseInt(cur.getString(cur
    .getColumnIndex(ContactsContract.Contacts.HAS_PHON E_NUMBER))) > 0) {
    // Query phone here. Covered next
    Cursor phones = ctx
    .getContentResolver()
    .query(ContactsContract.CommonDataKinds.Phone.CONT ENT_URI,
    null,
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
    + " = " + id, null, null);
    while (phones.moveToNext()) {
    String phoneNumberX = phones
    .getString(phones
    .getColumnIndex(ContactsContract.CommonDataKinds.P hone.NUMBER));
    // Log.i("Number", phoneNumber);

    phoneNumberX = phoneNumberX.replace(" ", "");
    phoneNumberX = phoneNumberX.replace("(", "");
    phoneNumberX = phoneNumberX.replace(")", "");
    if (phoneNumberX.contains(phoneNumber)) {
    phones.close();
    return true;

    }

    }
    phones.close();
    }

    }
    }
    } catch (Exception ex) {
    Log.i("f", ex.getMessage());

    }

    return false;
    }


    دسترسی ها :

        <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />

  40. #80

    نقل قول: این هم کد

    افزودن میانبر در صفحه اول (HomeScreen): همزمان با اجرای برنامه
    این کد رو تو اکتیویتی اصلی کپی کنید:

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
    if(!prefs.getBoolean("firstTime", false)) {
    // <---- run your one time code here
    Intent HomeScreenShortCut= new Intent(getApplicationContext(),
    MainActivity.class);


    HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
    HomeScreenShortCut.putExtra("duplicate", false);
    //shortcutIntent is added with addIntent
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "اسم برنامه");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESO URCE,
    Intent.ShortcutIconResource.fromContext(getApplica tionContext(),
    R.drawable.ic_launcher));
    addIntent.setAction("com.android.launcher.action.I NSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);

    Toast.makeText(getApplicationContext(), "آیکن این برنامه برای دسترسی سریع در صفحه اصلی افزوده شد", Toast.LENGTH_LONG).show();

    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("firstTime", true);
    editor.commit();
    }

    واینو تو منیفست پروژه:

    <uses-permission android:name="com.android.launcher.permission.INST ALL_SHORTCUT" />

صفحه 2 از 4 اولاول 1234 آخرآخر

تاپیک های مشابه

  1. با این کد میتوانید Recycle Bin را خالی کنید ...
    نوشته شده توسط Keramatifar در بخش برنامه نویسی در Delphi
    پاسخ: 4
    آخرین پست: پنج شنبه 26 آبان 1384, 14:51 عصر
  2. پاسخ: 2
    آخرین پست: سه شنبه 12 آبان 1383, 20:08 عصر
  3. این دیگه چیه؟ too many record are locked
    نوشته شده توسط aliasghar در بخش برنامه نویسی در Delphi
    پاسخ: 3
    آخرین پست: شنبه 08 فروردین 1383, 19:12 عصر
  4. با رعایت کردن این موارد هک نشوید
    نوشته شده توسط Mehrdad_Cracker در بخش امنیت در شبکه
    پاسخ: 3
    آخرین پست: سه شنبه 02 اردیبهشت 1382, 21:34 عصر
  5. کی می دونه این پیغام برای چیه؟
    نوشته شده توسط ghaum در بخش مسائل مرتبط با نصب و راه اندازی
    پاسخ: 3
    آخرین پست: شنبه 23 فروردین 1382, 12:14 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •