Sunday, November 23, 2014

شرکت نرم افزاری

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

بابا همش مشکله! تو رشته نرم افزار، چه تو کارشناسی چه تو ارشد فقط یه سری مهملات بار دانشجوها میکنن. بهترین تئوری های کاربردی مدیرتی فلان فلان رو وقتی تئوریک یاد میدن، دانشجو فقط حفط میکنه. این معلومات در نهایت تبدیل میشن به ابزار پاس کردن - یعنی مهملات.
چیزی که دانشجو باید یاد بگیره علاوه بر دانش تئوریک، تجربه عملی نحوه مدیریت یه پروژه تیمیه. این کجا به درد می خوره؟ معلومه خب، سر کار. وقتی فرد بدونه که به عنوان مدیر از اعضای تیم چه انتظاری داره می تونه بفهمه که مدیرش سر کار ازش چه انتظاراتی داره. اون وقته که سو تفاهم و نا رضایتی "معقول" میشه  و تنش کاری کاهش پیدا میکنه. بدون گرفتن وقت زیاد می تونن طرز نگاه هم رو به موضوع کاریشون درک کنن.
کدوممون یادمون میاد که تو دانشگاه یه پروژه تیمی رو انجام داده باشیم؟ اگه انجام دادیم، چه تجربه های مفیدی کسب کردیم؟ چه روش علمی رو برای انجام کار انتخاب کردیم؟ چقدر جواب داده؟

یه شرکت بزرگ نباید فقط به سابقه علمی کارمنداش اتکا کنه. باید برای نیروهای تازه واردش یه دوره کوتاه آشنایی با کار بزاره که حتما شامل آموزش کوچیک مدیریتی هم باشه...

Tuesday, November 18, 2014

Android Toast: Custom font or other things

Two things to do: Define a simple small layout for the custom toast and a simple startup sequence:

Toast background:
 <?xml version="1.0" encoding="utf-8"?>  
 <selector xmlns:android="http://schemas.android.com/apk/res/android">  
   <item>  
     <shape>  
       <solid android:color="@color/toast_back" />  
       <corners android:radius="3dp" />  
       <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />  
     </shape>  
   </item>  
 </selector>  

Toast layout:
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:orientation="vertical" android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:id="@+id/Toast_Root">  
   
   <TextView  
     android:padding="10dp"  
     android:id="@+id/Toast_Message"  
     android:background="@drawable/toast_back"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content" />  
 </LinearLayout>  

Sample startup sequence in a static method:
 public class Toast {  
   static private Activity mCurrentActivity;  
   static public void updateCurrentActivity(Activity act) {  
     mCurrentActivity = act;  
   }  
   
   static public void Show(int id) {  
     LayoutInflater inflater = mCurrentActivity.getLayoutInflater();  
     View layout = inflater.inflate(R.layout.toast,  
         (ViewGroup) mCurrentActivity.findViewById(R.id.Toast_Root));  
   
     TextView text = (TextView)layout.findViewById(R.id.Toast_Message);  
     text.setText(mCurrentActivity.getApplicationContext().getText(id));  
     android.widget.Toast toast = new android.widget.Toast(mCurrentActivity.getApplicationContext());  
     toast.setDuration(android.widget.Toast.LENGTH_SHORT);  
     toast.setView(layout);  
     toast.show();  
   }  
 }  

Monday, November 17, 2014

کد های تلفن همراه

کد های تلفن همراه ایران:

ردیف
شماره ناحیه
پیش شماره
استانهای موجود در ناحیه
1
ناحیه 1
0911
2
ناحیه 2
0912
3
ناحیه 3
0913
4
ناحیه 4
0914
5
ناحیه 5
0915
6
ناحیه 6
0916
7
ناحیه 7
0917
8
ناحیه 8
0918

جهت مشاهده پیش شماره خطوط شهرهای مختلف در استانها بر روی نام استان مورد نظر در لیست بالا کلیک نمایید
به جز شماره های بالا که مربوط به اپراتور اول یعنی همراه اول MCI (ارتباطات سیار TCI) می باشد
پیش شماره تلفن های همراه زیر از دیگر کد موبایل های ایران هستند که شامل سیم کارتهای اعتباری و دائم اپراتورهای مختلف بوده که به شرح ذیل میباشند :
9 0932 – شرکت تالیا ، Taliya (عرضه در کلیه شهرهای ایران)
4 0932 ، 0931 – اسپادان ، Spadan (عرضه در کلیه شهرهای ایران)
0934 – شبکه مستقل تلفن همراه کیش ، TKC (عرضه در جزیره کیش)
0910 ، 0919 – اپراتور اول ، همراه اول ، MCI (عرضه در کلیه شهرهای ایران)
0901 ، 0902 ، 0930 ، 0933 ، 0935 ، 0936 ، 0937 ، 0938 ، 0939 – اپراتور دوم ، ایرانسل ، Irancell (عرضه در کلیه شهرهای ایران)
0920 ، 0921 – اپراتور سوم ، رایتل ، تامین تلکام ، سازمان تامین اجتماعی ، Rightel (عرضه در شهرهای بزرگ ایران)

- منبع، پورتال آسمونی  http://www.asemooni.com/iran/phonebook/mobile-code#ixzz3JMXAIbyU

اگه می خوای ببینی یه شماره واسه کدوم کشور و کدوم اپراتوره:
https://www.numberingplans.com//?page=analysis&sub=phonenr

Thursday, November 13, 2014

Change Windows 8.1 default lock screen image

There are two points needing attention here! Lock screen image and Login screen color. For login screens currently there is no way to set an image.

Ok now. For the lock screen one, this is the path to group policies:

 Address: Computer Configuration\Administrative Templates\Control Panel\Personalization  
 Policy name: Force a specific default lock screen image  

Wednesday, November 12, 2014

Force RTL layouts in Android

Yup. I'm writing a Persian oriented application. Of course I should provide RTL layouts in my application and use Iranian locale. So what to do? In my custom Application class I use this to change the locale:

   @Override public void onCreate(){  
     super.onCreate();  
   
     Configuration newConfig = new Configuration();  
     newConfig.locale = new Locale("fa");  
     Locale.setDefault(newConfig.locale);  
     super.onConfigurationChanged(newConfig);  
     getBaseContext().getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());  
   }

For the RTL layout part, I use this approach to force RTL on SDK v17+:
First  add this option to Application section in AndroidManifest.xml:

 android:supportsRtl="true"  

Now add implement this function whereever in your application and call it on all Activity.onCreate event handlers:

 import android.annotation.TargetApi;  
 import android.os.Build;  
 import android.view.View;  
 import android.view.Window;  
   
 /**  
  * Created by Klaus on 11/13/2014.  
  */  
 public class RTLProvider {  
   @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)  
   static public void forceRTLIfSupported(Window win)  
   {  
     if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){  
       win.getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);  
     }  
   }  
 }  

Monday, November 3, 2014

Using custom fonts in Android

The bad news: One can not yet (as of today) use custom fonts on UI when designing application. Custom fonts can be loaded run time only using certain methods.
The good news: In my searches, I found ways to easily use custom fonts in applications. (Yeah, easily... as in easily creating a custom turkey)

My proposal is a system containing one package and some customizations. In the package, 5 files should be implemented and AndroidManifest.xml should be altered. An enumeration, a Heart, a FontProvider and a CustomTextView.
1: The enum: To use multiple custom typefaces in application, I created an enum holding different typeface values.

 public enum FontNames {  
   Yekan  
 }  

2: The FontProvider: This is a static class, though it can be implemented by singletons too. The purpose will be to provide fonts from a pre-built cache to waste as little memory as possible. (Android v2* had a bug which resulted in poor memory management for fonts. In certain conditions created fonts were not correctly freed)


 public class FontProvider {  
   static private Map<FontNames, Typeface> mCache;  
   
   static public void Initialize(){  
     mCache = new HashMap<FontNames, Typeface>();  
     mCache.put(FontNames.Yekan, Typeface.createFromAsset(Heart.getAssets(), "BYEKAN.TTF"));  
   }  
   
   static public Typeface GetFont(FontNames font) {  
     if(mCache == null || mCache.isEmpty())  
       return Typeface.defaultFromStyle(Typeface.NORMAL);  
   
     return mCache.get(font);  
   }  
 }  

3: Heart: Taking in mind that fonts are needed to be customized for a certain application, one can see the need to customize other features of the application. For this, a "HEART" is created to manage different custom elements of the application. The heart is designed again as a static class but can also be implemented as a singleton.

 public final class Heart {  
   static private AssetManager mAssets;  
   
   private Heart() {}  
   
   static public void Initialize(AssetManager assets)  
   {  
     mAssets = assets;  
     FontProvider.Initialize();  
   }  
   
   static public AssetManager getAssets(){  
     return mAssets;  
   }  
 }  
   

4: A CustomTextView: Since custom fonts are more easily implemented in the code than specified in XML, creating a custom control seems less hassle:

 public class TextView extends android.widget.TextView {  
   public TextView(Context context) {  
     super(context);  
     init(null);  
   }  
   
   public TextView(Context context, AttributeSet attrs) {  
     super(context, attrs);  
     init(attrs);  
   }  
   
   public TextView(Context context, AttributeSet attrs, int defStyle) {  
     super(context, attrs, defStyle);  
     init(attrs);  
   }  
   
   private void init(AttributeSet attrs) {  
     if(attrs != null)  
       setTypeface(FontProvider.GetFont(FontNames.Yekan));  
   }  
 }  
   

5: Create a custom application class that starts up the HEART:

 public class Application extends android.app.Application {  
   public Application(){ }  
   
   @Override public void onCreate(){  
     super.onCreate();  
     ir.gnco.shila.ui.Heart.Initialize(getAssets());  
   }  
 }  
   

6: Modify AndroidManifest.xml to load you application class instead of the default one:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="..." >  
   
   <application  
     android:name=".Application"  
     ... >  
   
      <activity>  
        ...  
      </activity>  
   </application>  
 </manifest>  
   

OK now. The hard part is finished. Just build your project and drag'n'drop your new TextView to any Activity you want.

.
.
.
.
PS: Just kidding. Copy your custom font in the assets folder. For AndroidStudio users: The place does not exist. Create it in <project>/app/src/main/assets