Search Results

Search found 55 results on 3 pages for 'typeface'.

Page 3/3 | < Previous Page | 1 2 3 

  • Need a fast programming language that can drive two printers

    - by Pete
    I have a rather unusual application that isn't working the way I need, and I hope someone here will have some suggestions or at least a direction to investigate. We have a museum exhibit that has a computer at the entrance driving two small receipt printers. There are two buttons on a console, wired to the left and right buttons of a disemboweled mouse. The two printers and associated buttons are for girls and boys, each button does a random selection from a database of names and prints a small ticket on the appropriate printer with a graphic image, a few words about the exhibit and the randomly chosen name. Conceptually all is well, but it hangs quite often. I got the project at the last minute, because the original designer got bogged down and couldn't deliver, so the exhibit's author asked me the day before opening, whether I could write something that would work. I did it in Word, since I am an experienced VBA programmer. Several other avenues I attempted first all lead to dead ends - one couldn't do graphics, another couldn't handle two printers, yet another couldn't change fonts and so on. The problem is that it simply isn't fast enough - Word can only drive one printer at a time and changing the active printer takes a long time. Not by office standards, where a second or two of delay before a printer starts working on your document is not an issue, but here I need more or less instant response. If kids press a button and nothing happens, they press it over and over until something does happen, resulting in maybe half a dozen commands being sent before the printer starts reacting. Sometimes it jams the program completely, since boys and girls will be pressing the two buttons simultaneously and Word locks up, and even when it doesn't jam, the printers then spit out a stream of tickets, making a mess. The kids start squabbling over which ticket is whose, pulling them out of the printers, snarling the paper tape, jamming the printer and generally making a mess of the whole affair, often necessitating the exhibit caretakers having to restart the computer and clear torn bits of paper out the printers. What I need is some sort of fast programming language that can drive two printers *-simultaneously-*, not the MSOffice claptrap of having to switch the active printer, that can react to both left and right mouse button click events, can print a small graphic image and can print in different font sizes and styles and. I don't need many, but it's not all in one typeface. Can anyone suggest what I might use for this? I don't even know if it's possible at all under Windows, whether the "single active printer" garbage is an Office artifact, or a Windows restriction. My little Commodore-64 twenty-five years ago had two printers attached to it and drove both simultaneously with no difficulties - it doesn't seem to me it should be such an impossible requirement today.

    Read the article

  • Who could ask for more with LESS CSS? (Part 2 of 3&ndash;Setup)

    - by ToStringTheory
    Welcome to part two in my series covering the LESS CSS language.  In the first post, I covered the two major CSS precompiled languages - LESS and SASS to a small extent, iterating over some of the features that you could expect to find in them.  In this post, I will go a little further in depth into the setup and execution of using the LESS framework. Introduction It really doesn’t take too much to get LESS working in your project.  The basic workflow will be including the necessary translator in your project, defining bundles for the LESS files, add the necessary code to your layouts.cshtml file, and finally add in all your necessary styles to the LESS files!  Lets get started… New Project Just like all great experiments in Visual Studio, start up a File > New Project, and create a new MVC 4 Web Application.  The Base Package After you have the new project spun up, use the Nuget Package Manager to install the Bundle Transformer: LESS package. This will take care of installing the main translator that we will be using for LESS code (dotless which is another Nuget package), as well as the core framework for the Bundle Transformer library.  The installation will come up with some instructions in a readme file on how to modify your web.config to handle all your *.less requests through the Bundle Transformer, which passes the translating onto dotless. Where To Put These LESS Files?! This step isn’t really a requirement, however I find that I don’t like how ASP.Net MVC just has a content directory where they store CSS, content images, css images….  In my project, I went ahead and created a new directory just for styles – LESS files, CSS files, and images that are only referenced in LESS or CSS.  Ignore the MVC directory as this was my testbed for another project I was working on at the same time.  As you can see here, I have: A top level directory for images which contains only images used in a page A top level directory for scripts A top level directory for Styles A few directories for plugins I am using (Colrizr, JQueryUI, Farbtastic) Multiple *.less files for different functions (I’ll go over these in a minute) I find that this layout offers the best separation of content types.  Bring Out Your Bundles! The next thing that we need to do is add in the necessary code for the bundling of these LESS files.  Go ahead and open your BundleConfig.cs file, usually located in the /App_Start/ folder of the project.  As you will see in a minute, instead of using the method Microsoft does in the base MVC 4 project, I change things up a bit.  Define Constants The first thing I do is define constants for each of the virtual paths that will be used in the bundler: The main reason is that I hate magic strings in my program, so the fact that you first defined a virtual path in the BundleConfig file, and then used that path in the _Layout.cshtml file really irked me. Add Bundles to the BundleCollection Next, I am going to define the bundles for my styles in my AddStyleBundles method: That is all it takes to get all of my styles in play with LESS.  The CssTransformer and NullOrderer types come from the Bundle Transformer we grabbed earlier.  If we didn’t use that package, we would have to write our own function (not too hard, but why do it if it’s been done). I use the site.less file as my main hub for LESS - I will cover that more in the next section. Add Bundles To Layout.cshtml File With the constants in the BundleConfig file, instead of having to use the same magic string I defined for the bundle virtual path, I am able to do this: Notice here that besides the RenderSection magic strings (something I am working on in another side project), all of the bundles are now based on const strings.  If I need to change the virtual path, I only have to do it in one place.  Nifty! Get Started! We are now ready to roll!  As I said in the previous section, I use the site.less file as a central hub for my styles: As seen here, I have a reset.css file which is a simple CSS reset.  Next, I have created a file for managing all my color variables – colors.less: Here, you can see some of the standards I started to use, in this case for color variables.  I define all color variables with the @col prefix.  Currently, I am going for verbose variable names. The next file imported is my font.less file that defines the typeface information for the site: Simple enough.  A couple of imports for fonts from Google, and then declaring variables for use throughout LESS.  I also set up the heading sizes, margins, etc..  You can also see my current standardization for font declaration strings – @font. Next, I pull in a mixins.less file that I grabbed from the Twitter Bootstrap library that gives some useful parameterized mixins for use such as border-radius, gradient, box-shadow, etc… The common.less file is a file that just contains items that I will be defining that can be used across all my LESS files.  Kind of like my own mixins or font-helpers: Finally I have my layout.less file that contains all of my definitions for general site layout – width, main/sidebar widths, footer layout, etc: That’s it!  For the rest of my one off definitions/corrections, I am currently putting them into the site.less file beneath my original imports Note Probably my favorite side effect of using the LESS handler/translator while bundling is that it also does a CSS checkup when rendering…  See, when your web.config is set to debug, bundling will output the url to the direct less file, not the bundle, and the http handler intercepts the call, compiles the less, and returns the result.  If there is an error in your LESS code, the CSS file can be returned empty, or may have the error output as a comment on the first couple lines. If you have the web.config set to not debug, then if there is an error in your code, you will end up with the usual ASP.Net exception page (unless you catch the exception of course), with information regarding the failure of the conversion, such as brace mismatch, undefined variable, etc…  I find it nifty. Conclusion This is really just the beginning.  LESS is very powerful and exciting!  My next post will show an actual working example of why LESS is so powerful with its functions and variables…  At least I hope it will!  As for now, if you have any questions, comments, or suggestions on my current practice, I would love to hear them!  Feel free to drop a comment or shoot me an email using the contact page.  In the mean time, I plan on posting the final post in this series tomorrow or the day after, with my side project, as well as a whole base ASP.Net MVC4 templated project with LESS added in it so that you can check out the layout I have in this post.  Until next time…

    Read the article

  • Why my button can trigger the UI to scroll and my TimerTask inside the activity can't?

    - by Spidey
    Long Story Short: a method of my activity updates and scrolls the ListView through an ArrayAdapter like it should, but a method of an internal TimerTask for polling messages (which are displayed in the ListView) updates the ListView, but don't scroll it. Why? Long Story: I have a chat activity with this layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#fff" > <ListView android:id="@+id/messageList" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stackFromBottom="true" android:transcriptMode="alwaysScroll" android:layout_weight="1" android:fadeScrollbars="true" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" > <EditText android:id="@+id/message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:id="@+id/button_send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send" android:onClick="sendMessage" /> </LinearLayout> </LinearLayout> The internal listView (with id messageList) is populated by an ArrayAdapter which inflates the XML below and replaces strings in it. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="false" android:background="#fff" android:paddingLeft="2dp" android:paddingRight="2dp" > <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="#00F" android:typeface="monospace" android:text="2010-10-12 12:12:03" android:gravity="left" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sender" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="#f84" android:text="spidey" android:gravity="right" android:textStyle="bold" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/body" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="14sp" android:padding="1dp" android:gravity="left" android:layout_below="@id/date" android:text="Mensagem muito legal 123 quatro cinco seis." android:textColor="#000" /> </RelativeLayout> The problem is: in the main layout, I have a EditText for the chat message, and a Button to send the message. I have declared the adapter in the activity scope: public class ChatManager extends Activity{ private EditText et; private ListView lv; private Timestamp lastDate = null; private long campaignId; private ChatAdapter ca; private List<ChatMessage> vetMsg = new ArrayList<ChatMessage>(); private Timer chatPollingTimer; private static final int CHAT_POLLING_PERIOD = 10000; ... } So, inside sendMessage(View v), the notifyDataSetChanged() scrolls the ListView acordingly, so I can see the latest chat messages automatically: public void sendMessage(View v) { String msg = et.getText().toString(); if(msg.length() == 0){ return; } et.setText(""); String xml = ServerCom.sendAndGetChatMessages(campaignId, lastDate, msg); Vector<ChatMessage> vetNew = Chat.parse(new InputSource(new StringReader(xml))); //Pegando a última data if(!vetNew.isEmpty()){ lastDate = vetNew.lastElement().getDateSent(); //Atualizando a tela vetMsg.addAll(vetNew); ca.notifyDataSetChanged(); } } But inside my TimerTask, I can't. The ListView IS UPDATED, but it just don't scroll automatically. What am I doing wrong? private class chatPollingTask extends TimerTask { @Override public void run() { String xml; if(lastDate != null){ //Chama o Updater xml = ServerCom.getChatMessages(campaignId, lastDate); }else{ //Chama o init denovo xml = ServerCom.getChatMessages(campaignId); } Vector<ChatMessage> vetNew = Chat.parse(new InputSource(new StringReader(xml))); if(!(vetNew.isEmpty())){ //TODO: descobrir porque o chat não está rolando quando chegam novas mensagens //Descobrir também como forçar o rolamento, enquanto o bug não for corrigido. Log.d("CHAT", "New message(s) acquired!"); lastDate = vetNew.lastElement().getDateSent(); vetMsg.addAll(vetNew); ca.notifyDataSetChanged(); } } } How can I force the scroll to the bottom? I've tried using scrollTo using lv.getBottom()-lv.getHeight(), but didn't work. Is this a bug in the Android SDK? Sorry for the MASSIVE amount of code, but I guess this way the question gets pretty clear.

    Read the article

  • half or quarter black screen in android

    - by Mike McKeown
    I have an android activity that when I launch sometimes (about 1 in 4 times) it only draws quarter or half the screen before showing it. When I change the orientation or press a button the screen draws properly. I'm just using TextViews, Buttons, Fonts - no drawing or anything like that. All of my code for initialising is in the onCreate(). In this method I'm loading a text file, of about 40 lines long, and also getting a shared preference. Could this cause a delay so that it can't draw the intent? Thanks in advance if anyone has seen anything similar. EDIT - I tried commenting out the loading of the word list, but it didn't fix the problem. Here is the activity <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainRelativeLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/blue_abstract_background" > <RelativeLayout android:id="@+id/relativeScore" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <TextView android:id="@+id/ScoreLabel" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:padding="10dip" android:text="SCORE:" android:textSize="18dp" /> /> <TextView android:id="@+id/ScoreText" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/ScoreLabel" android:padding="5dip" android:text="0" android:textSize="18dp" /> <TextView android:id="@+id/GameTimerText" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:minWidth="25dp" android:text="0" android:textSize="18dp" /> <TextView android:id="@+id/GameTimerLabel" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@id/GameTimerText" android:padding="10dip" android:text="TIMER:" android:textSize="18dp" /> /> </RelativeLayout> <RelativeLayout android:id="@+id/relativeHighScore" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/relativeScore" > <TextView android:id="@+id/HighScoreLabel" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:padding="10dip" android:text="HIGH SCORE:" android:textSize="16dp" /> <TextView android:id="@+id/HighScoreText" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/HighScoreLabel" android:padding="10dip" android:text="0" android:textSize="16dp" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_below="@+id/relativeHighScore" android:orientation="vertical" > <LinearLayout android:id="@+id/linearMissing" android:layout_width="fill_parent" android:layout_height="80dp" android:layout_gravity="center" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="2dp" android:background="@color/yellow_text" /> <TextView android:id="@+id/MissingWordText" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:layout_marginTop="25dp" android:text="MSSNG WRD" android:textSize="22dp" android:typeface="normal" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2dp" android:background="@color/yellow_text" /> <TableLayout android:id="@+id/buttonsTableLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableRow android:id="@+id/tableRow3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:paddingTop="5dp" > <Button android:id="@+id/aVowelButton" android:layout_width="66dp" android:layout_height="66dp" android:layout_gravity="center_horizontal" android:layout_marginBottom="10dp" android:layout_marginRight="5dp" android:background="@drawable/blue_vowel_button" android:text="@string/a" android:textColor="@color/yellow_text" android:textSize="30dp" /> <Button android:id="@+id/eVowelButton" android:layout_width="66dp" android:layout_height="66dp" android:layout_gravity="center_horizontal" android:layout_marginBottom="10dp" android:layout_marginRight="5dp" android:background="@drawable/blue_vowel_button" android:text="@string/e" android:textColor="@color/yellow_text" android:textSize="30dp" /> </TableRow> <TableRow android:id="@+id/tableRow4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" > <Button android:id="@+id/iVowelButton" android:layout_width="66dp" android:layout_height="66dp" android:layout_gravity="center_horizontal" android:layout_margin="5dp" android:background="@drawable/blue_vowel_buttoni" android:text="@string/i" android:textColor="@color/yellow_text" android:textSize="30dp" /> <Button android:id="@+id/oVowelButton" android:layout_width="66dp" android:layout_height="66dp" android:layout_gravity="center_horizontal" android:layout_margin="5dp" android:background="@drawable/blue_vowel_button" android:text="@string/o" android:textColor="@color/yellow_text" android:textSize="30dp" /> <Button android:id="@+id/uVowelButton" android:layout_width="66dp" android:layout_height="66dp" android:layout_gravity="center_horizontal" android:layout_margin="5dp" android:background="@drawable/blue_vowel_button" android:text="@string/u" android:textColor="@color/yellow_text" android:textSize="30dp" /> </TableRow> </TableLayout> <TextView android:id="@+id/TimeToStartText" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:textSize="24dp" /> <Button android:id="@+id/startButton" style="@style/yellowShadowText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" android:background="@drawable/blue_button_menu" android:gravity="center" android:padding="10dip" android:text="START!" android:textSize="28dp" /> </LinearLayout> </RelativeLayout> And the OnCreate() and a few methods: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_game); isNewWord = true; m_gameScore = 0; m_category = getCategoryFromExtras(); // loadWordList(m_category); initialiseTextViewField(); loadHighScoreAndDifficulty(); setFonts(); setButtons(); setStartButton(); enableDisableButtons(false); } private void loadHighScoreAndDifficulty() { //setting preferences SharedPreferences prefs = this.getSharedPreferences(m_category, Context.MODE_PRIVATE); int score = prefs.getInt(m_category, 0); //0 is the default value m_highScore = score; m_highScoreText.setText(String.valueOf(m_highScore)); prefs = this.getSharedPreferences(DIFFICULTY, Context.MODE_PRIVATE); m_difficulty = prefs.getString(DIFFICULTY, NRML_DIFFICULTY); } private void initialiseTextViewField() { m_startButton = (Button) findViewById(R.id.startButton); m_missingWordText = (TextView) findViewById(R.id.MissingWordText); m_gameScoreText = (TextView) findViewById(R.id.ScoreText); m_gameScoreLabel = (TextView) findViewById(R.id.ScoreLabel); m_gameTimerText = (TextView) findViewById(R.id.GameTimerText); m_gameTimerLabel = (TextView) findViewById(R.id.GameTimerLabel); m_timeToStartText = (TextView) findViewById(R.id.TimeToStartText); m_highScoreLabel = (TextView) findViewById(R.id.HighScoreLabel); m_highScoreText = (TextView) findViewById(R.id.HighScoreText); } private String getCategoryFromExtras() { String category = ""; Bundle extras = getIntent().getExtras(); if (extras != null) { category = extras.getString("category"); } return category; } private void enableDisableButtons(boolean enable) { Button button = (Button) findViewById(R.id.aVowelButton); button.setEnabled(enable); button = (Button) findViewById(R.id.eVowelButton); button.setEnabled(enable); button = (Button) findViewById(R.id.iVowelButton); button.setEnabled(enable); button = (Button) findViewById(R.id.oVowelButton); button.setEnabled(enable); button = (Button) findViewById(R.id.uVowelButton); button.setEnabled(enable); } private void setStartButton() { m_startButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { m_gameScore = 0; updateScore(); m_startButton.setVisibility(View.GONE); m_timeToStartText.setVisibility(View.VISIBLE); startPreTimer(); } }); }

    Read the article

  • Intent and OnActivityResult causing Activity to get restart Actuomatically : Require to solve this issues

    - by Parth Dani
    i am having 20 imageview and i am having 20 button for them when i click any 1 button it gives me option to select image from gallery or camera when i select any option for example galley it will take me to the gallery and let me select image from their and let me display those images on my imageview for respective button now the problem is sometimes when i do the whole above process my activity is getting restart actuomatically and all the image which were first selected get vanished from their imageview For Refernce my code is as follow: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.new_upload); // **************Code to get Road worthy number and VIN number value in // Shared Preference starts here************************ SharedPreferences myPrefs1 = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE); roadworthynumber = myPrefs1.getString(MY_ROADWORTHY, "Road Worthy Number"); vinnumber = myPrefs1.getString(MY_VIN, "VIN Number"); // **************Code to get Road worthy number and VIN number value in // Shared Preference ends here************************ // **************Code to create Directory AUSRWC starts // here************************ if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { cacheDir = new File(Environment.getExternalStorageDirectory() + File.separator + "AUSRWC" + File.separator); cacheDir.mkdirs(); } // **************Code to Create Directory AUSRWC ends // here************************ // *****************Assigning Button variable their Id declare in XML // file starts here***************** new_select1 = (Button) findViewById(R.id.new_select1); new_select2 = (Button) findViewById(R.id.new_select2); new_select3 = (Button) findViewById(R.id.new_select3); new_select4 = (Button) findViewById(R.id.new_select4); new_select5 = (Button) findViewById(R.id.new_select5); new_select6 = (Button) findViewById(R.id.new_select6); new_select7 = (Button) findViewById(R.id.new_select7); new_select8 = (Button) findViewById(R.id.new_select8); new_select9 = (Button) findViewById(R.id.new_select9); new_select10 = (Button) findViewById(R.id.new_select10); new_select11 = (Button) findViewById(R.id.new_select11); new_select12 = (Button) findViewById(R.id.new_select12); new_select13 = (Button) findViewById(R.id.new_select13); new_select14 = (Button) findViewById(R.id.new_select14); new_select15 = (Button) findViewById(R.id.new_select15); new_select16 = (Button) findViewById(R.id.new_select16); new_select17 = (Button) findViewById(R.id.new_select17); new_select18 = (Button) findViewById(R.id.new_select18); new_select19 = (Button) findViewById(R.id.new_select19); new_select20 = (Button) findViewById(R.id.new_select20); // *****************Assigning Button variable their Id declare in XML // file ends here***************** // *****************Assigning Image variable their Id declare in XML // file starts here***************** new_selectimage1 = (ImageView) findViewById(R.id.new_selectImage1); new_selectimage2 = (ImageView) findViewById(R.id.new_selectImage2); new_selectimage3 = (ImageView) findViewById(R.id.new_selectImage3); new_selectimage4 = (ImageView) findViewById(R.id.new_selectImage4); new_selectimage5 = (ImageView) findViewById(R.id.new_selectImage5); new_selectimage6 = (ImageView) findViewById(R.id.new_selectImage6); new_selectimage7 = (ImageView) findViewById(R.id.new_selectImage7); new_selectimage8 = (ImageView) findViewById(R.id.new_selectImage8); new_selectimage9 = (ImageView) findViewById(R.id.new_selectImage9); new_selectimage10 = (ImageView) findViewById(R.id.new_selectImage10); new_selectimage11 = (ImageView) findViewById(R.id.new_selectImage11); new_selectimage12 = (ImageView) findViewById(R.id.new_selectImage12); new_selectimage13 = (ImageView) findViewById(R.id.new_selectImage13); new_selectimage14 = (ImageView) findViewById(R.id.new_selectImage14); new_selectimage15 = (ImageView) findViewById(R.id.new_selectImage15); new_selectimage16 = (ImageView) findViewById(R.id.new_selectImage16); new_selectimage17 = (ImageView) findViewById(R.id.new_selectImage17); new_selectimage18 = (ImageView) findViewById(R.id.new_selectImage18); new_selectimage19 = (ImageView) findViewById(R.id.new_selectImage19); new_selectimage20 = (ImageView) findViewById(R.id.new_selectImage20); // ****Assigning Image variable their Id declare in XML file ends // here***************** // **************Creating Dialog to give option to user to new_select // image from gallery or from camera starts here**************** final String[] items = new String[] { "From Camera", "From Gallery" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item, items); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("select Image"); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { if (android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED)) { Intent intent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE); File file = new File(Environment .getExternalStorageDirectory(), "/AUSRWC/picture" + ".jpg"); mImageCaptureUri = Uri.fromFile(file); try { Toast.makeText(getBaseContext(), "Click Image", Toast.LENGTH_SHORT).show(); intent.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); intent.putExtra("return-data", true); startActivityForResult(intent, PICK_FROM_CAMERA); } catch (Exception e) { e.printStackTrace(); } } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } dialog.cancel(); } else { Intent intent = new Intent(); Toast.makeText(getBaseContext(), "Select Image", Toast.LENGTH_SHORT).show(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE); } } }); dialog = builder.create(); // **************Creating Dialog to give option to user to new_select // image from gallery or from camera ends here**************** final Animation animAlpha = AnimationUtils.loadAnimation(this, R.anim.anim_alpha); // Animation Code for displaying Button // Clicked. // ********************Image 1 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 1; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 1 button code ends // here******************************* // ********************Image 2 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 2; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 2 button code ends // here******************************* // ********************Image 3 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select3.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 3; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 3 button code ends // here******************************* // ********************Image 4 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select4.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 4; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 4 button code ends // here******************************* // ********************Image 5 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select5.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 5; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 5 button code ends // here******************************* // ********************Image 6 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select6.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 6; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 6 button code ends // here******************************* // ********************Image 7 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select7.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 7; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 7 button code ends // here******************************* // ********************Image 8 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select8.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 8; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 8 button code ends // here******************************* // ********************Image 9 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select9.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 9; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 9 button code ends // here******************************* // ********************Image 10 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select10.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 10; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 10 button code ends // here******************************* // ********************Image 11 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select11.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 11; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 11 button code ends // here******************************* // ********************Image 12 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select12.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 12; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 12 button code ends // here******************************* // ********************Image 13 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select13.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 13; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 13 button code ends // here******************************* // ********************Image 14 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select14.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 14; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 14 button code ends // here******************************* // ********************Image 15 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select15.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 15; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 15 button code ends // here******************************* // ********************Image 16 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select16.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 16; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 16 button code ends // here******************************* // ********************Image 17 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select17.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 17; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 17 button code ends // here******************************* // ********************Image 18 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select18.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 18; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 18 button code ends // here******************************* // ********************Image 19 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select19.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 19; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 19 button code ends // here******************************* // ********************Image 20 button code starts // here******************************* if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)) { new_select20.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.startAnimation(animAlpha); buttonpressed = 20; dialog.show(); } }); } else { Toast.makeText(getBaseContext(), "Please insert SdCard First", Toast.LENGTH_SHORT).show(); } // ********************Image 20 button code ends // here******************************* } // *************************When Back Button is Pressed code begins // here************************************* @Override public void onBackPressed() { Toast.makeText(new_upload.this, "Sorry You are not allowed to go back", Toast.LENGTH_SHORT).show(); return; } // *************************When Back Button is Pressed code ends // here************************************* // ***********************To get Path of new_selected Image code starts // here************************************ public String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, null, null, null); if (cursor == null) return null; int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } // ***********************To get Path of new_selected Image code ends // here************************************ // **********************Picture obtained from the camera or from gallery // code starts here************** @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //path = ""; Log.e("","requestCode="+requestCode); switch (requestCode){ case PICK_FROM_FILE: if (resultCode == Activity.RESULT_OK) { mImageCaptureUri = data.getData(); path = getRealPathFromURI(mImageCaptureUri); // from Gallery Log.e("", "Imagepath from gallery=" + path); if (path == null) path = mImageCaptureUri.getPath(); // from File Manager if (path != null) { dialog1 = ProgressDialog.show(new_upload.this, "", "Processing Please wait...", true); new ImageDisplayTask().execute(); } } break; case PICK_FROM_CAMERA: if (resultCode == Activity.RESULT_OK) { try { path = mImageCaptureUri.getPath(); Log.e("", "Imagepath from Camera =" + path); // bitmap = BitmapFactory.decodeFile(path); } catch (Exception e) { e.printStackTrace(); } if (path != null) { dialog1 = ProgressDialog.show(new_upload.this, "", "Processing Please wait...", true); //new ImageDisplayTask1().execute(); new ImageDisplayTask().execute(); } } break; default: } } // ********************Picture obtained from the camera or from gallery code // ends here********************************************* // ******************Image Display on Button when new_selected from gallery // Ashynch Code starts here******************************** class ImageDisplayTask extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... unsued) { Bitmap src = BitmapFactory.decodeFile(path); Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); //Bitmap dest = Bitmap.createScaledBitmap(src, src.getWidth(),src.getHeight(), true); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String dateTime = sdf.format(Calendar.getInstance().getTime()); // reading local `` String timestamp = dateTime + " " + roadworthynumber; SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); String dateTime1 = sdf1.format(Calendar.getInstance().getTime()); Imagename = dateTime1.toString().trim().replaceAll(":", "") .replaceAll("-", "").replaceAll(" ", "") + roadworthynumber + ".jpg"; Canvas cs = new Canvas(dest); Paint tPaint = new Paint(); tPaint.setTextSize(100); tPaint.setTypeface(Typeface.SERIF); tPaint.setColor(Color.RED); tPaint.setStyle(Style.FILL); cs.drawBitmap(src, 0f, 0f, null); float height = tPaint.measureText("yY"); cs.drawText(timestamp, 5f, src.getHeight() - height + 5f, tPaint); try { dest.compress(Bitmap.CompressFormat.JPEG, 70, new FileOutputStream(new File(cacheDir, Imagename))); dest.recycle(); src.recycle(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onProgressUpdate(Void... unsued) { } @Override protected void onPostExecute(String serverresponse) { String error = "noerror"; Display currentDisplay = getWindowManager().getDefaultDisplay(); int dw = currentDisplay.getWidth(); int dh = currentDisplay.getHeight() - 100; Log.e("", "width= " + dw + " Height= " + dh); try { BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); bmpFactoryOptions.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile( Environment.getExternalStorageDirectory() + "/AUSRWC/" + Imagename, bmpFactoryOptions); int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / (float) dh); int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) dw); if (heightRatio > 1 && widthRatio > 1) { if (heightRatio > widthRatio) { bmpFactoryOptions.inSampleSize = heightRatio; } else { bmpFactoryOptions.inSampleSize = widthRatio; } } bmpFactoryOptions.inJustDecodeBounds = false; bmp = BitmapFactory.decodeFile( Environment.getExternalStorageDirectory() + "/AUSRWC/" + Imagename, bmpFactoryOptions); if (buttonpressed == 1) { new_selectimage1.setImageBitmap(bmp); //Image set on ImageView } else if (buttonpressed == 2) { new_selectimage2.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 3) { new_selectimage3.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 4) { new_selectimage4.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 5) { new_selectimage5.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 6) { new_selectimage6.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 7) { new_selectimage7.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 8) { new_selectimage8.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 9) { new_selectimage9.setImageBitmap(bmp);//Image set on ImageView } else if (buttonpressed == 10) { new_selectimage10.setImageBitmap(bmp); } else if (buttonpressed == 11) { new_selectimage11.setImageBitmap(bmp); } else if (buttonpressed == 12) { new_selectimage12.setImageBitmap(bmp); } else if (buttonpressed == 13) { new_selectimage13.setImageBitmap(bmp); } else if (buttonpressed == 14) { new_selectimage14.setImageBitmap(bmp); } else if (buttonpressed == 15) { new_selectimage15.setImageBitmap(bmp); } else if (buttonpressed == 16) { new_selectimage16.setImageBitmap(bmp); } else if (buttonpressed == 17) { new_selectimage17.setImageBitmap(bmp); } else if (buttonpressed == 18) { new_selectimage18.setImageBitmap(bmp); } else if (buttonpressed == 19) { new_selectimage19.setImageBitmap(bmp); } else if (buttonpressed == 20) { new_selectimage20.setImageBitmap(bmp); } } catch (Exc

    Read the article

< Previous Page | 1 2 3